Java anonymous object
Java-Anonymous Object One anonymous object new Car().num = 5;Attribute has no meaning new Car().run(); method is meaningful i.e. it doesn’t make sense to use properties of anonymous objects And it makes sense to use its methods How to use: When the method of an object is only called once, it can be done with an anonymous object, which is simpler If you call a member of an object, you must give the object a name 2 Below are two pictures Non-anonymous objects Copyright statement: This article is an original article by the blogger and may not be reproduced without the blogger’s permission. Java-Anonymous Object
java anonymous object
Java-Anonymous Object An anonymous object new Car().num = 5; attribute has no meaning new Car().run(); method makes sense Even using properties of anonymous objects doesn’t make sense And it makes sense to use its methods How to use: When the method on the object is called only once, it can be done with an anonymous object, which is simpler If you call a member of an object, you must give the object a name Two Below are two pictures non-anonymous object Copyright statement: This article is an original article of the blogger, and shall not be reproduced without the permission of the blogger. Java-Anonymous Object