今天来介绍java 各版本的新特性,一篇文章让你了解
java8 新特性 Java8 主要包括的新特性有: 函数式接口 如果一个接口只有一个抽象方法,那么该接口就成为一个函数式接口。同时java还配套引入@FunctionalInterface注解, 该注解主要式用于强制表示一个接口必须是一个函数式接口,但是不是必须的。 @FunctionalInterface public interface DemoFuncInterface1 { void apply(); } public interface DemoFuncInterface2 { void apply(); } public interface DemoFuncInterface3 { void apply(); void apply2(); } public interface DemoFuncInterface4 { default void apply() {}; } 上面4个例子中DemoFuncInterface1、DemoFuncInterface2都是 函数式接口。但是第三个、第四个都不是,而且将@FunctionalInterface标记 在第三、第四个上编译都会报错。 使用函数式接口demo: public class testDemo{ public void testFunc(DemoFuncInterface demoFuncInterface ,