If you are using a generic class or collection type with generics and you pass in a primitive type - short, int, long, float, double, char, boolean, you will get the below error either at the runtime or compile-time,
Compile Time Error: Type argument cannot be of primitive type
Run Time Error:
java: unexpected type
required: reference
found: int
Code with Compilation Error:
List<int> list = new ArrayList<>();
list.add(10);
Fix:
You need to replace the primitive type with its respective Object type,
int -> Integer
byte -> Byte
short -> Short
long -> Long
float -> Float
double -> Double
char -> Character
Fixed Code:
List<Integer> list = new ArrayList<>();
list.add(10);
If you are using an IDE like Eclipse or IntelliJ, you should get a hint on how to replace it,

More Posts related to Java,
- How to install Java 11 on Mac
- Get Client IP address from HTTP Response in Java
- SharePoint Open in the client application document opens in browser
- How to verify if java is installed on the computer and get version detail
- Java - Check if array contains the value
- Your JBoss Application Server 7 is running However you have not yet added any users to be able to access the admin console
- How to run Java Unit Test cases with Apache Maven?
- What Java version is used for Minecraft 1.18
- List of jar files for Jax-ws (SOAP) based Java Web Services
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- Convert Instant timestamp into LocalDateTime Java Code Example
- Java - Calculate time taken for the code to execute in milliseconds or nanoseconds
- Create simple struts2 project using maven commands
- Java - PatternSyntaxException
- List of Online Java compiler with console
- Minecraft Java Edition
- How to declare and initialize Array in Java Programming
- [Solved] com.sun.xml.ws.transport.http.servlet.WSServletContextListener ClassNotFoundException
- Java XML-RPC 3.1.x based web service example
- Simple Struts 2 Tutorial in eclipse with tomcat 7 server
- Java 8 foreach loop code examples
- Java -Day of the week using Java 8 DayOfWeek Enum
- Java 8 - Convert List to Map Examples
- Java: TimeZone List with GMT/UTC Offset
- list of jars required for hibernate 4.x.x
More Posts:
- How to add border to Android TextView - Android
- Get cURL command from Chrome Inspect Network HTTP URL - cURL
- Get Browser Screen Width and Height dynamically using jQuery - jQuery
- Android Launch! The connection to adb is down, and a severe error has occured - Android
- This Toast was not created with Toast.makeText() : Android RuntimeException - Android
- Remove duplicate lines using Notepad++ - NotepadPlusPlus
- List of Java Major Minor Version Numbers - Java
- How to update SharePoint List Item programmatically using C#.Net - SharePoint