generics Generics in Java

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!


  • class MyClass<T1, T2 extends CharSequence> implements Comparable<MyClass> //...
  • interface MyListInterface<T extends Serializable> extends List<T> //...
  • public <T1, T2 extends Instant> T1 provideClone(T1 toClone, T2 instant> //...
  • public static List<CharSequence> safe(Collection<? extends CharSequence> l) { return new ArrayList<>(l);}
  • Set<String> strings = Collections.singleton("Hello world");
  • List<CharSequence> chsList = safe(strings);


Type erasure limits reflection, though that is not JVM specific, for example Ceylon uses reified generics.

Existential type support is not necessarily supported by other languages in this form: Kotlin supports it through type projections.

Got any generics Question?