函数式接口作为方法的参数练习
public class RunnableDemo { public static void main(String[] args) { //使用匿名类调用方法 startThread(new Runnable() { @Override public void run() { System.out.println(Thread.currentThread().getName()+"线程启动了"); } }); //使用Lambda表达式调用方法 startThread(() -> System.out.println(Thread.currentThread().getName()+"线程启动了")); } private static void startThread(Runnable r){ new Thread(r).start(); } }
学习的博客多用于在笔记中,防止笔记过于臃肿,所以将样例及运行结果放在博客中,后以超链接的形式记录在笔记中,所以有些博文过于单薄。如果有小伙伴遇到问题欢迎评论,看到就会回复,学渣一枚,加油努力。