The Anonymous object in Java.
In Java, you can create the object without the reference variable. This object has no reference and can be used only once.
This type of objects which have no reference associated with it is called the anonymous object.
Anonymous objects can be only used once At the time of the creation.
Example of an Anonymous Object in Java
You can see that we have created the anonymous class in Java which has no reference. In above example, while invoking the add() and mul() methods there is two instances created for the both method and that both instances we can not use again without referencing it.
What is the Advantage of Anonymous Object in Java?
There is no direct use of the anonymous object in Java. It can also not help you to increase the performance or the speed of the execution.
However, you can save some of the CPU cycles of creating the reference of the object if you are using the object only once. Apart from that, you can increase the readability of the code as per your convenience and your comfort.
You can also find the very rare discussion of this type of object over the internet because of its almost rare usability.
Over to You
So here we have discussed the Anonymous objects in Java if you liked the post then you can share it with your friends on social media. You can also like Code Puran’s social media profile to get the latest post on your timeline itself.