[英]Getting “Type mismatch: cannot convert from int to Object” error at the time of initiation of integer inside Object Array in java
public class objArrayPractice {
public static void main(String[] args) {
Object ar []= new Object [4];
ar[0]= 12;
}
}
when I write ar[0]= 12; 当我写ar [0] = 12时; I am getting the error: "Type mismatch: cannot convert from int to Object" 我收到错误消息:“类型不匹配:无法从int转换为Object”
To convert 12
into an object you need al least Java 1.5, this is called Autoboxing 要将12
转换为对象,您至少需要Java 1.5,这称为自动装箱
Autoboxing and unboxing was introduced in Java 1.5 to automatically convert primitive type into boxed primitive( Object or Wrapper class) Java 1.5中引入了自动装箱和拆箱功能,可将原始类型自动转换为装箱的原始类型(Object或Wrapper类)
So be sure to have on both machines a Java version >= 1.5 因此,请确保两台计算机上的Java版本均大于等于1.5
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.