Re: reflection newInstance



"Mike Phelps" <mphelps@xxxxxxxxxxx> wrote in message
news:433088c6.172770550@xxxxxxxxxxxxxxxxx
> 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


.



Relevant Pages


Loading