I wonder why generic methods which return nothing void
are (or can be) declared this way:
public static <E> void printArray( E[] inputArray ) {
// Display array elements
for ( E element : inputArray ){
System.out.printf( "%s ", element );
}
System.out.println();
}
It seems like <E>
is the type of the returned object, but the method returns nothing in fact. So what is the real meaning of <E>
in this case specifically and in generic methods generally?
This question suits one of my old notes. I hope this illustration helps: