Files
anna 481bc252f3 switch tests on new inference
(cherry picked from commit d2cbf3f2833104c3a0381059b0d6ef8ac0b3c94c)
2013-11-25 16:47:38 +01:00

32 lines
900 B
Java

class CyclicInference {
interface Execute {
void execute();
}
/**
* Lambda wrapper for expression-like lambdas
*
* @param lambda
* @param <I> interface which lambda class implements (derived by compiler via type inference)
* @param <T> lambda class having function code to be executed
* @return I interface implemented by lambda
*/
private static <I, T extends I> I lambdaWrapper(final T lambda) {
return (I)lambda;
}
/**
* How expression-like lambdas returning void can be wrapped
*/
public void lambdaWithOneExpressionReturningVoid() {
Execute sayHello = lambdaWrapper(() -> System.out.println("Hello"));
sayHello.execute();
}
public static void main(String[] args) {
CyclicInference lam = new CyclicInference();
lam.lambdaWithOneExpressionReturningVoid();
}
}