public class Anonymousfunction {
public void test(Test test){
Test test2 = test;
test2.show(); // 執(zhí)行結(jié)果:這是類的 show 方法
Method [] methods = test2.getClass().getDeclaredMethods();
System.out.println(methods.length);
for(Method method : methods) // 對象里為什么只有一個 display 函數(shù)呢 ,沒有 show 函數(shù)?
System.out.println(method.getName());
}
public static void main(String [] args){
Anonymousfunction anonymousfunction = new Anonymousfunction();
anonymousfunction.test(new Test (){
public void display () {
System.out.println("這是 Test 類的 display 方法");
}
});
}
}
class Test{
public void show(){
System.out.println("這是類的 show 方法");
}
}
問題描述 就是上面的那一行注釋,是在沒想明白
匿名函數(shù)中的使用
慕田峪7331174
2019-02-20 08:20:20