Today,The haze is back.so crazy and whole sky is grey.so i m in bad mood.
The good news is i m always studing
>---------------so First is Java8 FuncionInterface.
1、it mean single abstract method interface.it has one abstract method compare with normal interface.相比于正常接口,它只有一个抽象方法。so this is the first character ,this is the main mean for this design.
2、you can use lamda decelop it.it will become easy and simple.
我认为一个抽象方法是它的核心,你可以使用简便的lamda表达式来实现接口。
3、if you have many abstract functions ,the compiler will give you error message.
如果你在此接口中写多个抽象方法,编译器将报错。
4、it allows you to have multiple normal methods and static methods.它允许你拥有多个正常实现的方法和静态方法.
5、All the same time,it allows you to define methods where it from Object that it is common.
并且它允许你定义object中的通用方法。
For Example
接口:
@FunctionalInterface
public static interface Converter<F, T> {
T convert(F from);
}
实现:
Converter<String, Integer> integerConverter1 = (from) -> Integer.valueOf(from);
Integer converted1 = integerConverter1.convert("123");
System.out.println(converted1); // result: 123
>>---------------In the java class you can define the generic(泛型) T,K..... Only do it for Object Head.在类初始做泛型,使用它
>>>---------------If you compare Objecet A and Object B,you can implement Compareble Interface。如果你想比较多个对象的一个字段,你可以实现此接口去比较。