Professional Documents
Culture Documents
Generics Functional Interface
Generics Functional Interface
Generics Functional Interface
Scanner;
import java.util.function.*;
s1.setVar1("Bryan");
s1.setVar2("Vern");
System.out.println(s1.getVar1());
System.out.println(s1.getVar2());
si.show(true);
};
BiFunction<Integer, Integer, String> bifunction = (a , b) -> { return a + " " +
b; };
UnaryOperator<Integer> unary = a -> { return a * a; };
BinaryOperator<Integer> binary = (a, b) -> { return a + b; };
consume.accept("Bi","Consume");
System.out.println( supply.get() );
if ( predict.test( 18 ) ) {
System.out.println("You are an adult");
} else {
System.out.println("You are not an adult");
}
System.out.println( bifunction.apply(10, 25) );
System.out.println( unary.apply(10) );
System.out.println( binary.apply(50, 25) );
}
}
@FunctionalInterface
interface SampleInterface<T> {
void show(T a);
}
// primitive
// int, short, byte, char, boolean, double, float, long
// reference
// String, Integer, Double, Character, Boolean, Long, Short, Byte, Float,
// String, Class, Interface
// Generics
class OtherExample<A, B> {
A sample1;
B sample2;
A sample1(int a, int b) {
return sample1;
}
B sample2() {
return sample2;
}
}
public T getVar1() {
return var1;
}
public D getVar2() {
return var2;
}