Java – we can create runnable objects as its interfaces
•
Java
I see a sample code that uses the new runnable (), which is an anonymous inner class
Runnable runnable = new Runnable() { public void run() { int option = (int) (Math.random() * 4); switch (option) { case 0: x.a(); break; case 1: x.b(); break; case 2: y.a(); break; case 3: y.b(); break; } } };
Any help is appreciated I'm new here.
Solution
Yes We can. This is called an anonymous inner class It can not only run, but also be created anonymously for any interface
It is recommended to read this article
https://docs.oracle.com/javase/tutorial/java/javaOO/anonymousclasses.html
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
二维码