Curly braces in “new” expression? (e.g. “new MyClass() { … }”)

寵の児 提交于 2019-11-27 01:55:45

This is the syntax for creating an instance of anonymous class that extends Handler. This is part of Java.

Bhavik Ambani

This is happned when you create the instance reference of the Interface. For example I want to create the instance of the interface Runnable with the class, then I can create it by creating an anonymous class for the same and override the run() method of the interface. You can understand well by looking at the another example other then you stated below.

Runnable runnable = new Runnable() {

    public void run() {
        // TODO Auto-generated method stub

    }
};
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!