[Fix] java: incompatible types: java.lang.String cannot be converted to int


Example.java:6:21
java: incompatible types: java.lang.String cannot be converted to int

In Java you may get incompatible types compilation errors when you try to save incompatible type value in a specific data type which does not support it.

The error message "incompatible types: java.lang.String cannot be converted to int" occurs in when you try to assign a value of type String to a variable of type int, which is not possible because they are different data types.

Examples:
public class Example {
    public static void main(String[] args) {

        int myInt = "Harry";  //Required type: int Provided: String
    }
}
int myInt = "25"; //Required type: int Provided: String 
Java incompatible types String cannot be converted to int
-




Have Questions? Post them here!