Can a primitive value be considered an object in java?

When I started using Java, it was meant to me that we have two different types:

Objects (strings, from classes, println, etc)
primitive values (int, double, char)

I just returned with a professor, where this difference will mean the difference between the two answers. When I asked my professor for clarification, he told me that primitive values ​​can be objects.

Who is here, and can anyone give me any evidence? The proof would be something official sound, and I would choose it as the answer, and also awarded you some notorious Internet.

+4
source share
3 answers

Can a primitive value be considered an object?

Answer No.

JLS claims

Java : (§4.2) (§4.3). , , , , : (§4.2) (§4.3).

,

Java

,

(§8), (§9), (§4.4) (§10).

, the null type the null reference

null, null (§3.10.7, §15.8.1), .

...

- .

JLS , Boxing Conversion .

.

, , , . , .

+1

. int Integer.

, Java , (int autoboxes as Integer) auto-unboxed (Integer unboxes as int) , (Integer, Long ..), ( , ), . , , .

, (), int, Integer, ; , , Object ( ), , .

+10

, int , Integer. , autoboxing.

:

Integer foo = 4; // 4 is really an int

, . Class, int.class.

, .

Object vs primitive Java. . ( java , ).

+2
source

Source: https://habr.com/ru/post/1532564/


All Articles