java: incompatible types: double cannot be converted to java.lang.Integer
java: incompatible types: double cannot be converted to java.lang.Integer
java: incompatible types: float cannot be converted to java.lang.Double
java: incompatible types: int cannot be converted to java.lang.Boolean
java: incompatible types: byte cannot be converted to java.lang.Character
One of the reasons for the incompatible types is that you are using generics with collections and passing a wrong type to a specific type,
Exmple:1. public static void main(String[] args) {
2. List<Integer> list = new ArrayList<>();
3. list.add(10.0);
4. }
In the above example, we have a list of type Integer, and at line 3 we are trying to add a double to it, so you get a type safety compilation type error,
Required type: Integer
Provided: double
But if this happens at runtime you will get an error,

For this example, if you expect the types for the list to hold doubles as well, change the type from Integer -> Double.
Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!