Java – what are the uses of objects of type object
•
Java
I saw the code below the exercise in the scjp book
Object obj = new Object();
First of all, I think this may be a mistake because I didn't use such a statement Now I understand that this is a valid statement
I just want to know the practical use of this, if any What can you do with an object of type object (instead of a class derived from object)?
Solution
This code declares a reference of object type and assigns it a newly assigned object instance
Now, instances of class object may seem meaningless But they do have practical uses One such use is locking:
... synchronized (obj) { ... } ...
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码