简体   繁体   中英

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; I am getting the error: "Type mismatch: cannot convert from int to Object"

To convert 12 into an object you need al least Java 1.5, this is called Autoboxing

Autoboxing and unboxing was introduced in Java 1.5 to automatically convert primitive type into boxed primitive( Object or Wrapper class)

So be sure to have on both machines a Java version >= 1.5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM