java8中的Lamba表達式

1、什麼情況有下可以使用lamba

在函數式接口中可以使用

2、什麼是函數式接口

只有一個抽象方法的接口稱爲函數式接口,同時將這個抽象方法稱爲函數描述符

3、java8中新增了哪些函數式接口

Predicate 的boolean test(T var),其中原始類型特化有IntPredicate,LongPredicate,DoublePredicate

Consumer的void accept(T var),原始類型特化有IntConsumer,LongConsumer,DoubleConsumer

Function的R apply(T var),原始類型特化有IntFunction,IntToDoubleFunction,IntToLongFunction,LongFunction,LongToDoubleFunction, LongToIntFunction,ToDoubleFunction,ToIntFunction,ToLongFunction

BiPredicate的boolean test(T t, U u)

BiConsumer的void accept(T t, U u),原始類型特化有ObjDoubleConsumer,ObjIntConsumer,ObjLongConsumer

BiFunction的R apply(T t, U u),原始類型特化有ToDoubleBiFunction,ToIntBiFunction,ToLongBiFunciton

Supplier的T get(),原始類型特化有BooleanSupplier,DoubleSupplier,IntSupplier,LongSupplier

UnaryOperator的T apply(T t), 原始類型特化有IntUnaryOperator, LongUnaryOperator, DoubleUnaryOperator

BinaryOperator的T apply(T t1, T u1),原始類型特化有IntBinaryOperator, DoubleBinaryOperator, LongBinaryOperator

4、lamba函數在捕獲時有哪些要求

對於實例變量和靜態變量無限制,對於局部變量必須顯示聲明爲final或者事實上是final

5、方法引用有哪幾種方法

一種是靜態方法,一種是實例對角方法。都是採用class|obj::methodName

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章