[Haskell-cafe] Re: What I wish someone had told me...

Robert Greayer robgreayer at yahoo.com
Thu Oct 16 13:02:13 EDT 2008

--- On Thu, 10/16/08, Jonathan Cast <jonathanccast at fastmail.fm> wrote:

> Can I have HashSet<Integer>?  Could I construct
> HashSet<?>, if I did?


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();

works fine..


More information about the Haskell-Cafe mailing list