Hi Guys,
Object obj = Class.forName("java.lang.Integer").newInstance(); throws
a java.lang.InstantiationException. why? what does it mean? How can I
build an Integer with a default value when all I have is a string:
"java.lang.Integer". It is from an xml file that contains type of an
object, It could also be java.lang.Float or java.lang.Double.
Thanks.
Oliver Wong - 20 Sep 2005 23:20 GMT
> Object obj = Class.forName("java.lang.Integer").newInstance(); throws
> a java.lang.InstantiationException. why? what does it mean?
What does it say on
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/InstantiationException.html ?
> How can I
> build an Integer with a default value when all I have is a string:
> "java.lang.Integer".
You cannot. The Integer class
(http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html) doesn't
have a "default" value. You have to specify a value.
> It is from an xml file that contains type of an
> object, It could also be java.lang.Float or java.lang.Double.
See http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Float.html and
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Double.html
- Oliver
Roedy Green - 21 Sep 2005 00:39 GMT
>Object obj = Class.forName("java.lang.Integer").newInstance(); throws
>a java.lang.InstantiationException. why? what does it mean? How can I
>build an Integer with a default value when all I have is a string:
>"java.lang.Integer". It is from an xml file that contains type of an
>object, It could also be java.lang.Float or java.lang.Double.
Integer has no default constructor. Since it is immutable, an Integer
(0) created that way would not be a very useful beast.

Signature
Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.