Curly braces in “new” expression? (e.g. “new MyClass() { … }”)
问题 What do the curly braces do there ? handler1 = new Handler() { public void handleMessage() { } }; object = new Class_Name() {}; ? This syntax exists only on Android or Java also? And what is it called in Java? Thank for your helps. 回答1: This is the syntax for creating an instance of anonymous class that extends Handler . This is part of Java. 回答2: 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