+ 1

I noticed that int X; and Integer X; in Java can mean two different things. Is there a difference? Why is that the case?

Java

12th May 2018, 10:53 AM
okon fortune sam
okon fortune sam - avatar
3 ответов
0
Yes it’s a special object that works just like the primitive version, you would use this version in generics since it only works on classes
12th May 2018, 11:27 AM
TurtleShell
TurtleShell - avatar
+ 1
int is a primitive type, Integer is the class for it.
12th May 2018, 10:57 AM
TurtleShell
TurtleShell - avatar
+ 1
OK so when I want to declare and initialize a variable as Integer x = 2; instead of int x = 5; does it mean I just declared and initialized a class?
12th May 2018, 11:23 AM
okon fortune sam
okon fortune sam - avatar