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

Richard O'Keefe ok at cs.otago.ac.nz
Wed Oct 15 21:43:56 EDT 2008


On 16 Oct 2008, at 9:01 am, Daryoush Mehrtash wrote:
> I am not sure how say in a Java language a constructor can "conjure  
> up a value of an unknown type".

... Class anUnknownClass;
     Object anInstance;
     anInstance = anUnknownClass.getConstructor().newInstance();

If you know that the constructor will require arguments of
types T1 and T2, and you have suitable values v1, v2,

     anInstance =
       anUnknownClass.getConstructor(T1, T2).newInstance(v1, v2);

will do the job.




More information about the Haskell-Cafe mailing list