Search code examples
javaclassintegerwrapperprimitive

Java primitive data fields in object wrappers


I was looking through the documentation for primitive wrappers in Java.

While I understand the utility of all the extra functionality provided by the methods, I don't seem to understand how the object stores the primitive in the first place. There doesn't seem to be any primitive final int.

EDIT: I learnt that Java documentation only shows public fields and methods, and after going through source code see a private int field. Just to confirm, it's then as simple as the compiler doing autoboxing/autounboxing through the public constructor to set the value ?


Solution

  • If you go to the source code of java.lang.Integer you will find

     private final int value;
    

    The reason that you don't see it in the API documentation, is that private attributes and methods are not included in the documentation.