Last active
May 11, 2021 09:51
-
-
Save 95Rajitha/4ab7f411bbdf1e50d65d661d875de4d9 to your computer and use it in GitHub Desktop.
Method level type erasure for Unbound
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
// Following method decleration with generic types | |
public static <E> void countElements(E[] array) { | |
private int count=0; | |
for (E element : array) { | |
count++; | |
} | |
System.out.println(count); | |
} | |
// compiler replaces the type parameter E with Object | |
public static <E> void countElements(Object[] array) { | |
private int count=0; | |
for (Object 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