

The difference between the wrapper class reference and the user defines the clas...
source link: https://www.codesd.com/item/the-difference-between-the-wrapper-class-reference-and-the-user-defines-the-class-reference-in-java.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

The difference between the wrapper class reference and the user defines the class reference in java
Suppose I have a custom class, say Test.
Test test = new Test(); // test is the reference.
Now when I print the value of test, it returns the hashcode .
Now consider,
Integer i = new Integer(10);
When I print the value of i
, it returns 10.
Can someone help me to understand what exactly is the difference here? I believe both are object references, but for wrapper class reference, it returns the value of the object it is pointing to.
When you create a new class, it inherits the method toString()
from Object
. Integer
class overrides that method to return the inner value.
Related Articles
What is the difference between a Windows game library and a class library?
What is the difference between a domain class diagram and a design class diagram?
What is the difference between initiating a class and inheriting from a class
What is the difference between an abstract class and a class with only protected constructors? (.NET)
What is the difference between having a class as final and having a class builder as private
What is the difference between & ldquo; Vector :: operator = & rdquo; And & ldquo; Vector :: assign & rdquo;
What are the differences between R.styleable, R.style and R.attr?
What is the difference between new in a builder and new in a member statement?
What is the difference between a static member variable and a namespace variable?
What is the difference between Dim v As String () and Dim v () As String?
What is the difference between TPC-C, TPC-E and TPC-H benchmark?
What is the difference between n * fun (n-1) and fun (n-1) * n
What is the difference between a regular Rails application and a Rails API?
What is the difference between didMove (to display: SKView) and didMoveToView (view: SKView)?
What is the difference between POCL (Portable Computing Language) and OpenCL?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK