标签:thread stat ++ string main interface ati class 并且
只能是一个方法
//匿名内部类,必须借助接口或父类
new Thread (new Runnable() {
public void run() {
for(int i=0;i<5;i++)
{
System.out.println("me");
}
}
}).start();
//使用lambda简化,将接口名和方法名去掉,只要参数和方法体
new Thread (()-> {
for(int i=0;i<5;i++)
{
System.out.println("me");
}
}).start();
**例子:**
public class hh {
//内部类
static class like2 implements ilike
{
public void lambda()
{
System.out.println("2");
}
}
public static void main(String[]args)
{
ilike like =new like();
like=new like2();
like.lambda();
//匿名内部类,借助ilike接口实现
like =new ilike()
{
public void lambda()
{
System.out.println("3");
}
};
like.lambda();
//lambda
like=()->{
System.out.println("4");
};
like.lambda();
}
}
interface ilike{
void lambda();
}
class like implements ilike{
public void lambda()
{
System.out.println("i like");
}
}
标签:thread stat ++ string main interface ati class 并且
原文地址:https://blog.51cto.com/14437184/2427421