what is the advantage of using anonymous class in java? | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

what is the advantage of using anonymous class in java?

the subclass will automatically overide the superclass method. doesn't it?

16th Jan 2018, 9:33 PM
aliakbar sultani
1 Resposta
0
Probably for encapsulation mostly. Anything you can do with an anonymous class you could also do with a nested class or a normal class, but if it's a one time use thing there's no need to do that. And yes it will override superclass methods where applicable. Check out some examples of the use of Google's Predicate class
17th Jan 2018, 7:50 AM
Dan Walker
Dan Walker - avatar