任何接口,如果只包含唯一一个抽象方法,那么它就是函数式接口(Function Interface)
public interface Runnable{ public abstract void run(); }1. 实现类
public class TestLamda { public static void main(String[] args){ Like like; like = new Like(); like.Lamda(); } } interface ILike { public void Lamda(); } //实现类 class Like implements ILike{ @Override public void Lamda(){ System.out.println("我喜欢"); } }2. 静态内部类
public class TestLamda { //静态内部类 static class Like implements ILike{ @Override public void Lamda(){ System.out.println("我喜欢"); } } public static void main(String[] args){ Like like; like = new Like(); like.Lamda(); } } interface ILike { public void Lamda();3. 局部内部类
public class TestLamda { public static void main(String[] args){ //局部内部类 class Like implements ILike{ @Override public void Lamda(){ System.out.println("我喜欢"); } } ILike like; like = new Like(); like.Lamda(); } } interface ILike { public void Lamda(); }4. 匿名内部类
public class TestLamda { public static void main(String[] args){ ILike like; like = new ILike(){ @Override public void Lamda() { System.out.println("我喜欢"); } }; like.Lamda(); } } interface ILike { public void Lamda(); }5. Lamda表达式
public class TestLamda { public static void main(String[] args){ ILike like; like = () ->{ System.out.println("我喜欢"); }; like.Lamda(); } } interface ILike { public void Lamda(); }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)