我們先看下這個接口的定義
@FunctionalInterface
public interface UnaryOperator<T> extends Function<T, T> {
/**
* Returns a unary operator that always returns its input argument.
*
* @param <T> the type of the input and output of the operator
* @return a unary operator that always returns its input argument
*/
static <T> UnaryOperator<T> identity() {
return t -> t;
}
}
這個接口繼承Function接口,Funtion接口,定義了一個apply的抽象類,接收一個泛型T對象,並且返回泛型R對象
關於Funtcion的意思以及用法,可以移步這邊Function接口的詳細;
這個接口,只接收一個泛型參數T,集成Function接口,也就是說,傳入泛型T類型的參數,調用apply後,返回也T類型的參數;這個接口定義了一個靜態方法,返回泛型對象的本身;
具體用法,可以參照Function接口詳細
UnaryOperator<Integer> dda = x -> x + 1;
System.out.println(dda.apply(10));// 11
UnaryOperator<String> ddb = x -> x + 1;
System.out.println(ddb.apply("aa"));// aa1
1.lambda表達式
《java8 Lambda表達式簡介》
《java8 lambda表達式,方法的引用以及構造器的引用》
2.函數式接口
《java8 函數式接口簡介》
3.stream接口操作
《JAVA8 Stream接口,map操作,filter操作,flatMap操作》
《JAVA8 stream接口 distinct,sorted,peek,limit,skip》
《java8 stream接口 終端操作 forEachOrdered和forEach》
《java8 stream接口 終端操作 toArray操作》
《java8 stream接口 終端操作 min,max,findFirst,findAny操作》
《java8 stream接口終端操作 count,anyMatch,allMatch,noneMatch》
《java8 stream接口 終端操作 collect操作》
4.其他部分