Powered by Blogger.

Erasure of type parameters in Generic Method arguments

The Java compiler erases type parameters in generic method arguments. Let us consider the following example to demonstrate two things:
  • To demonstrate erasure of type parameters in generic method arguments
  • To count number of occurrences of an element in an array
IGenericMethod.java:

GenericMethodImpl.java:

GenericMethodTest.java:

Output:
Number of occurences of element one in an array is: 3

Compile the above source code and inspect using javap command as shown in the picture below. See what Java Compiler has done.


0 comments:

Post a Comment