This article uses an example to deepen the understanding of anonymous inner classes.
Topic:
Package object-oriented; interface In{void method ();} Class test{//complements the code by anonymous inner class}public class Unknownnameclass {public static void main (string[] args) {test.function (). method ();}}
Analyze This sentence test.function (). method ();
In the test class there is a static method function () without parameters, the return value is not determined first, and this method calls the methods method, indicating that the return value of the function is an object that can call method methods, then is the subclass of in. An anonymous subclass object in which the function should return in.
The supplemental code is as follows:
public static in function () {return new in () {public void method () {//TODO auto-generated Method stub}};}
Upward downward, forward backward reasoning is very necessary in programming, need to strengthen the practice.
This article is from the "line of the World" blog, please be sure to keep this source http://4259297.blog.51cto.com/4249297/1656474
The idea of Java programming-Anonymous inner class