I
Ian
I am new to java class loading. In using it, I have two questions based
on the following code:
Class cc = Class.forName("G2");
G2 g = (G2)cc.newInstance();
1. When calling newInstance() to initialize "g", should G2 have to have
a default constructor without any parameters (i.e. public G2() {...}) ?
If yes, is there anyway to get around this if every G2's constructor
has at least one parameter? If no, how to call newInstance() in a
proper way?
2. What if G2 is a Java Generic class, e.g., G2<String, Int>? I tried
it. Except some "parameterize" warning messages at compile time, it
works fine. But my question is, is it safe?
Thanks.
on the following code:
Class cc = Class.forName("G2");
G2 g = (G2)cc.newInstance();
1. When calling newInstance() to initialize "g", should G2 have to have
a default constructor without any parameters (i.e. public G2() {...}) ?
If yes, is there anyway to get around this if every G2's constructor
has at least one parameter? If no, how to call newInstance() in a
proper way?
2. What if G2 is a Java Generic class, e.g., G2<String, Int>? I tried
it. Except some "parameterize" warning messages at compile time, it
works fine. But my question is, is it safe?
Thanks.