newInstance() with generics howto?

H

hiwa

How could we 'clean up'(no ct error, no ct warning, no rt error nor
exception)
the following code? I tried everything conceivable and failed in all of
them.
------------------
import java.util.*;
import java.lang.reflect.*;

public class GetMethod{
public static void main(String[] args) {
Object obj = null;
Class<Hashtable> clazz = Hashtable.class;
Class<Class> claxx = Class.class;
try {
Method method = claxx.getMethod("newInstance");
obj = method.invoke(clazz);
}
catch (Exception e) {
e.printStackTrace();
}
Hashtable<String,String> ht = (Hashtable<String,String>)obj;
ht.put("foo", "bar");
System.out.println(ht.get("foo"));
}
}
-----------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top