aspose file tools*
The moose likes Java in General and the fly likes reflection  - Constructor . newInstance (Object  ??) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "reflection  - Constructor . newInstance (Object  ??)" Watch "reflection  - Constructor . newInstance (Object  ??)" New topic
Author

reflection - Constructor . newInstance (Object ??)

Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
Hi there,
I need to create an object wich I don't know (the only thing wich I'm sure is that one of its Constructor takes an org.jdom.Element parameter).

The reflection api gives the opportunity to get a new istance of the Object from a Constructor using primitive parameters.

But my Object Constructor accept an org.jdom.Element as parameter. How can I create a new istance?



Thanks in advance.


trying to decode a woman mind....
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

What's wrong with the code you've shown? If you were trying to pass a primitive, then maybe I'd have to explain how to use a wrapper. But what you've done here is fine. What problem are you having?


[Jess in Action][AskingGoodQuestions]
Alessandro Ilardo
Ranch Hand

Joined: Dec 23, 2005
Posts: 218
At the moment the problem is that I can't compile it (I guess for the reason I mentioned before).

This's the message coming out while the compiler runs:

C:\...\HandleXml.java:82: '.class' expected
obj = cons.newInstance(Object[] {item});
C:\...\HandleXml.java:82: ')' expected
obj = cons.newInstance(Object[] {item});
2 errors
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

obj = cons.newInstance(new Object[] {item});
 
jQuery in Action, 2nd edition
 
subject: reflection - Constructor . newInstance (Object ??)