Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

reflection - Constructor . newInstance (Object ??)

 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Alessandro Ilardo
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
obj = cons.newInstance(new Object[] {item});
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic