I am sorry, Please ignore the my earlier post:
Check this:
Hi,
According to me,
Now if compiler allows us following:
Map<String, Set<Object>> m = new HashMap<String, Set<Object>>(); ---> m.getClass() ---> HashMap<String, Set<Object>>
but in the method create you are using:
Class<T> --> <T> --> <String, Set<Object>>
That is why it is asking you to define m with type parameter...
if you change :
public static<T> T create(Class cls) throws Exception{
T instance = cls.newInstance();
return instance;
}
It should not ask...
point here is that T and <T> are different..!!
T ---> HashMap
and
<T> is <String,Set<Object>> so overall you are returning type T from create method, that lead us to
Map<String, Set<Object>> map = create(m.getClass() ===> new HashMap();
Thats why you are getting the Unchecked Warning..
I think you should try
T<T> instanse = cls.newInstance();
I dont have JAVA5 on my system, So I can not compile this program for you
Please correct me If I am wrong
