This week's book giveaway is in the Testing forum. We're giving away four copies of Data Structures the Fun Way: An Amusing Adventure with Coffee-Filled Examples and have Jeremy Kubica on-line! See this thread for details.
I want to show following excerpt from "core java volume -1 fundamentals" ..
Type Variables Are Not Valid in Static Contexts of Generic Classes
You cannot reference type variables in static fields or methods. For example, the follow-
ing clever idea won’t work:
If this could be done, then a program could declare a Singleton<Random> to share a random
number generator and a Singleton<JFileChooser> to share a file chooser dialog. But it can’t
work. After type erasure there is only one Singleton class, and only one singleInstance field.
For that reason, static fields and methods with type variables are simply outlawed.
So in our case
so you need to make it ..
In the second case , instance method is dynamically invoked to return the Class type object,
so it doesnt't generate any error..
Still i want more experts to have a look at this query..
The problem is due to the generic syntax. Generic types don't mean anything at runtime, so ArrayList<Integer>.class, ArrayList<String>.class and ArrayList.class all mean the same at runtime as the actual class is ArrayList and the generic type is just for compile time type safety...