Working with partially unknown types is possible with Java 5, so its silent appeal to your example in Java 8:
public static void main(String... args) { use((Quacks & Waddles)Mixin::create); } private static <Duck extends Quacks & Waddles> void use(Duck duck) { duck.quack(); duck.waddle(); } interface Quacks extends Mixin { default void quack() { System.out.println("Quack"); } } interface Waddles extends Mixin { default void waddle() { System.out.println("Waddle"); } } interface Mixin { void __noop__(); static void create() {} }
Thus, the ability to do the same with var in Java 10 also allows you to do the same as before, but with slightly smaller source code. And the ability to do the same thing as before, but with less template code is exactly what var , regardless of whether you use intersection types or not.
Holger
source share