Skip to content

Instantly share code, notes, and snippets.

@finalfantasia
Last active May 8, 2021 16:32
Show Gist options
  • Save finalfantasia/4df421c22897e6dc623ef5147d5f7e5f to your computer and use it in GitHub Desktop.
Save finalfantasia/4df421c22897e6dc623ef5147d5f7e5f to your computer and use it in GitHub Desktop.
Java Generics

Terms

  • Generic Type
  • Generic Method
  • Type Parameter
  • Type Argument
  • Parameterized Type
  • Type Erasure
  • Wildcard (?)

Example

class GenericType <TypeParameter1 (extends | super Bound+)?> {
    TypeParameter1 field;
    
    public int genericMethod1 (TypeParameter1 t) {
        return 0;
    }
    
    public <TypeParameter2 (extends | super Bound+)?> int genericMethod2 (TypeParameter2 t) {
        return 0;
    }
    
    public int genericMethod3 (GenericType <? (extends | super Bound+)?> t) {
        return 0;
    }
}

GenericType <TypeArgument> instanceOfParameterizedType = new GenericType <> ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment