Can anyone please explain me any situation where these anonymous classes are useful?? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Can anyone please explain me any situation where these anonymous classes are useful??

5th Jul 2018, 7:04 PM
Aditya Manchanda
Aditya Manchanda - avatar
1 Answer
+ 1
If you are talking about Java, it is (was) commonly used to subclass `Runnable` or similar. For example maybe you have a "runInAnHour" function that runs a piece of code in an hour. Then you can runInAnHour(new Runnable(){ void run(){ // this runs in an hour } });
5th Jul 2018, 7:51 PM
Schindlabua
Schindlabua - avatar