Synthetic Class in Java

后端 未结 13 1741
广开言路
广开言路 2020-11-29 17:15

What is a synthetic class in Java? Why should it be used? How can I use it?

13条回答
  •  借酒劲吻你
    2020-11-29 17:31

    If I get it right, a synthetic class is one generated on the fly, without having to give it an explicit name. For example:

    //...
    Thread myThread = new Thread() {
             public void run() {
               // do something ...
             }
           };
    myThread.start();
    //...
    

    This creates a synthetic subclass of Thread and overrides its run() method, then instantiates it and starts it.

提交回复
热议问题