package testLambda;
import java.util.function.IntUnaryOperator;
/**
* lambda的遞歸
* @author P H
* @date 2018/8/31 15:48
*/
public class LambdaRecursion {
//IntUnaryOperator 表示對單個int值的操作數的操作,產生一個int值結果。 這是int的int的原始類型專業化。
static IntUnaryOperator fact;
public static void main(String[] args) {
//如果聲明的名字的在作用域中,那麼lambda就可以引用自身
//如實現遞歸,注意必須先聲明
fact=x->{
System.out.print(x+"\t");
return x>0?x:fact.applyAsInt(x+1) ;
};
fact.applyAsInt(-4);
}
}