Skip to content

Instantly share code, notes, and snippets.

@deepak
Last active January 6, 2016 08:36
Show Gist options
  • Save deepak/b9f458479e64338452ab to your computer and use it in GitHub Desktop.
Save deepak/b9f458479e64338452ab to your computer and use it in GitHub Desktop.
Generic Classes and Subtyping in Java

https://docs.oracle.com/javase/tutorial/java/generics/inheritance.html

interface PayloadList<E,P> extends List<E> {
    void setPayload(int index, P val);
}

class NewList implements PayloadList<Integer, String> {
  //...implement interface methods..
}

// Polymorphism
List<Integer> pl = new NewList(); // is valid
List<String> pl = new NewList();  // is invalid
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment