In Java 8 the lambda expression is introduced to help with the reduction of boilerplate code. If the interface has only one method it works fine. I
I usually create a static factory method directly in the interface:
public inteface I1 {
void show1();
void show2();
public static I1 of(Runnable show1, Runnable show2) {
return new I1() {
void show1() { show1.run(); }
void show2() { show2.run(); }
};
}
}
Usage:
I1 i1 = I1.of(() -> System.out.println("show1"), () -> System.out.println("show2"));