[Haskell-cafe] Re: What I wish someone had told me...
Richard O'Keefe
ok at cs.otago.ac.nz
Wed Oct 15 22:02:31 EDT 2008
On 16 Oct 2008, at 12:09 pm, Jonathan Cast wrote:
>> I am not sure how say in a Java language a constructor can "conjure
>> up
>> a value of an unknown type".
>
> Well, that's the point. It can't, in Haskell or in Java. If you
> understand that --- that you can't call the default constructor of a
> class that is not statically known at compile time
If you understand that about Java, then you don't understand Java.
Java reflection means that compile-time types are backed up by
runtime objects belonging to Type in general, to Class if they
are class types. It also means that you can discover the
default constructor by using aClass.getConstructor(), and you
can invoke it by using .newInstance().
If it were not possible to do this, Java would not get much
use out of its ability to load new classes at run time.
More information about the Haskell-Cafe
mailing list