
16 Oct
2008
16 Oct
'08
1:02 p.m.
--- On Thu, 10/16/08, Jonathan Cast
Can I have HashSet<Integer>? Could I construct HashSet>, if I did?
Yes: HashSet<?> blah = (HashSet<?>) hashSetClass.newInstance(); ... compiles, and won't throw an exception if hashSetClass truly is the class object for HashSet. Pretty useless, because you can't put anything *into* a HashSet> object... blah.add("foo"); // doesn't typecheck... but you can do: HashSet<String> blah = (HashSet<String>) hashSetClass.newInstance(); blah.add("foo"); works fine..