Created
February 16, 2018 13:05
-
-
Save stefanobaghino/fb4a54844e038369a2105bd3d8504ef3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Animal { | |
String salutation(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Cage<T> { | |
public final T value; | |
public Cage(T value) { | |
this.value = value; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Dog implements Animal { | |
@Override | |
public String salutation() { | |
return "bark"; | |
} | |
public static void main(String[] args) { | |
Cage<? extends Animal> cage = new Cage(new Dog()); | |
System.out.println(cage.value.salutation()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment