有人能为我提供一个常规嵌套类的简单示例,然后将同一个类重写为匿名内部类吗?
答案 0 :(得分:1)
以下是示例:
public class Outer {
public static class NestedStatic implements Runnable {
public void run(){
doSomething();
}
public static void main(String[] args){
Thread nestThread=new Thread(new NestedStatic());
nestThread.start();
// now anonymous:
Thread anonThread=new Thread(new Runnable(){
public void run(){
doSomethingElse();
});
anonThread.start();
}
}