账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    匿名函数中的使用
    51
    0

    public class Anonymousfunction {

    public void test(Test test){
        Test test2 = test;
        test2.show();   // 执行结果:这是类的 show 方法
        Method [] methods = test2.getClass().getDeclaredMethods();
        System.out.println(methods.length);
        for(Method method : methods)     // 对象里为什么只有一个 display 函数呢 ,没有 show 函数?
            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 方法");
    }

    }

    问题描述 就是上面的那一行注释,是在没想明白

    1
    打赏
    收藏
    点击回答
        全部回答
    • 0
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部