Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to assign primitives to Object array in Eclipse

I am initiating object array as below:

Object a[] = new Object[4];

a[0] = 1; //while assigning integer value, am getting an error: "Type mismatch: Cannot convert Integer to Object
a[1] = 'A'; //while assigning char value, am getting an error: "Type mismatch: Cannot convert char to Object
a[2] = 12.33//while assigning integer value, am getting an error: "Type mismatch: Cannot convert double to Object
a[3] = "Hello"; //Accepting only string values.

PLease suggest where went wrong? is it configuration issue? I am using:

Java Version jdk1.8.0_151,
jre1.8.0_151,

Eclipse Java EE IDE for Web Developers.
Version: Oxygen.2 Release (4.7.2)
Build id: 20171218-0600
like image 382
Praveen Avatar asked Jan 27 '23 05:01

Praveen


1 Answers

This is exactly the error message you would be getting if you are using a compiler compliance level lower than 5. Note that this is different from the Java version on your system. See the fix here https://stackoverflow.com/a/24591529/11595728 .

like image 89
SDJ Avatar answered Jan 31 '23 20:01

SDJ