黑马程序员技术交流社区
标题:
匿名内部类作参数传递
[打印本页]
作者:
ypenghui
时间:
2016-5-14 21:59
标题:
匿名内部类作参数传递
实现以下代码:
class test{
public static void main(String[] args){
outer.method().show();
//分析outer.method()为对象;show为方法
//outer.静态方法
}
}
interface Inter{
void show();
}
class outer{
//补齐以下代码
public static Intter method(){
return new Inter(){
public void show(){}
};
}
}
复制代码
作者:
yaolv7
时间:
2016-5-14 22:10
哥们,看清楚,别激动,Inter不是Intter.....
还有,类名单词首字母记得大写....
不一定非要用Inter
class Outer{
//补齐以下代码
public static Outer method(){
return new Outer(){
public void show(){}
};
}
public void show(){}
}
复制代码
class Outer{
//补齐以下代码
public static Inner method(){
return new Inner(){
public void show(){}
};
}
static class Inner {
void show(){}
}
}
复制代码
其实原理是一样的,都是返回一个匿名类
作者:
ypenghui
时间:
2016-5-14 22:27
对的,谢谢大神指点
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2