Why can't pass Integer and string to Object parameters in Java method
I'm new to Intellij IDEA and I wrote the following code but it cannot be compiled successfully (Integers and Strings can't be passed to the method with Object parameters). What is strange is that this code works in Eclipse with JDK1.8.
I really can't figure out where the problem is. Does it have something to do with the Intellij setting?
Error:
Error: (12, 18) java: incompatible type: int cannot be converted to java.lang.Object
Code:
public static void func(Object obj){
System.out.print(obj.toString());
}
public static void main(String argv[]){
func(3);
}
Go in to your Project Structure - ctrl + alt + shift + s
Go to Project Settings
-> Project
Ensure Project Language Level
is what you require (in your case, I think you need at least 5, but you might as well use 8).
上一篇: 更改最大上传文件大小