[Haskell-cafe] Re: What I wish someone had told me...
Jonathan Cast
jonathanccast at fastmail.fm
Thu Oct 16 13:00:06 EDT 2008
On Thu, 2008-10-16 at 10:02 -0700, Robert Greayer wrote:
>
>
> --- On Thu, 10/16/08, Jonathan Cast <jonathanccast at fastmail.fm> 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
More information about the Haskell-Cafe
mailing list