几种Lambda形式

import java.util.function.BiConsumer;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
public class FunctionType
{
public Supplier noParamLambda()
{
return () -> 3;
}
public Supplier noParamLambda2()
{
return new Supplier()
{
public Number get()
{
return 3;
}
};
}

public Supplier noParamLambda3()
{
    Supplier a = () -> 3;//不能写成Object a = 
    return a;
}
//**********************************************
public Function oneParamLambda()
{
    return a -> a +" post";
}

public Function oneParamLambda2()
{
    return new Function()
            {
                public String apply(String a)
                {
                    return a + " post";
                }
            };
}

public Function oneParamLambda3()
{
    Function b = a -> a +" post";
    return b;
}

public Predicate oneParamRtBooleanLambda()
{
    return x -> x != null && x.indexOf("hello") >= 0;
}

public  UnaryOperator oneParamWithSameReturnType()
{
    return a -> a;
}

//************************************************
public BiFunction twoParamLambda()
{
    return (a, b) -> a + b;
}

public BiFunction twoParamLambda2()
{
    return new BiFunction()
            {
                public String apply(String a, String b)
                {
                    return a + b;
                }
            };
}

public BiFunction twoParamLambda3()
{
    BiFunction w = (a, b) -> a + b;
    return w;
}

public  BinaryOperator twoParamWithSameTypeAndReturnSameType()
{
    return (a, b) -> a;
}

//*******************************************
public Consumer noReturnLambda()
{
    return a -> System.out.println(a);
}

public BiConsumer noReturnLambda2()
{
    return (a, b) -> System.out.println(a+" "+b);
}
//*******************************************
public  Function partial2To1(BiFunction bf, T t)
{
    return u -> bf.apply(t, u);
}

public  Supplier partial1To0(Function bf, U u)
{
    return () -> bf.apply(u);
}

//*******************************************
public  Function> curry(BiFunction bf)
{
    return t -> (u -> bf.apply(t,u));
}

}

你可能感兴趣的:(几种Lambda形式)