publicinterfaceRunnable{/**
* When an object implementing interface <code>Runnable</code> is used
* to create a thread, starting the thread causes the object's
* <code>run</code> method to be called in that separately executing
* thread.
* <p>
* The general contract of the method <code>run</code> is that it may
* take any action whatsoever.
*
* @see java.lang.Thread#run()
*/publicabstractvoidrun();}
对于函数式接口,我们可以通过lambda表达式老创建该接口的对象。
示例:
package lambda;
/**
* @Description
* @Author wangkui
* @Date 2022-07-28 16:25
* @Version 1.0
*/
public class TestLambda2 {
public static void main(String[] args) {
ILove love = (int a) -> System.out.println("i love you -->" + a);
//继续简化.
love = a -> System.out.println("i love you -->" + a);
love.love(1);
}
}
interface ILove {
/**love
* @param a a
*/
void love(int a);
}
class Live implements ILove {
@Override
public void love(int a) {
System.out.println("i love you -->" + a);
}
}