Skip to content

Instantly share code, notes, and snippets.

@95Rajitha
Created May 11, 2021 09:49
Show Gist options
  • Save 95Rajitha/add5ade335087059427c977a2a658563 to your computer and use it in GitHub Desktop.
Save 95Rajitha/add5ade335087059427c977a2a658563 to your computer and use it in GitHub Desktop.
bounded type erasure for method level erasure
//method declartation to elaborate bounded method type parameter
public static <E extends Comparable<E>> void countElements(E[] array) {
private int count =0;
for (E element : array) {
count++;
}
System.out.println(count);
}
//Replacing E with Comparable
public static void countElements(Comparable[] array) {
private int count =0;
for (Comparable element : array) {
count++;
}
System.out.println(count);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment