
16 Oct
2008
16 Oct
'08
1 p.m.
On Thu, 2008-10-16 at 10:02 -0700, Robert Greayer wrote:
--- On Thu, 10/16/08, Jonathan Cast
wrote: 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.
But I can't say new HashSet>()?
Pretty useless, because you can't put anything *into* a HashSet> object...
Even if my client hands my a ? object?
blah.add("foo"); // doesn't typecheck...
but you can do: HashSet<String> blah = (HashSet<String>) hashSetClass.newInstance(); blah.add("foo");
works fine..
jcc