Class newInstance() with parameters
Is it possible to use newInstance to create an instance of a Class where the constructor is expecting parameters? I know the API lists newInstance as having no parameters and calling essentially a no-arg constructor, but is there any type of design that would allow me to create an instance with parameters?
[314 byte] By [
Bart69a] at [2007-11-27 10:49:27]

Class.getDeclaredConstructor()
Constructor.newInstance()
Although that's just code, and rather anti-design IMO. Although I don't know what you need and why you might need it, so I can't suggest a different way. It might be the most suitable way for you.
The previous architect went hogwild with reflection so now I have to wrestle with it at every turn. At the point I need to instantiate an object, all I know is the String representation of its name. However, I want to create the object with parameters in its constructor. I'd rather do this a different way, but the architect's questionable love for reflection is forcing me to do otherwise.
> The previous architect went hogwild with reflection
> so now I have to wrestle with it at every turn. At
> the point I need to instantiate an object, all I know
> is the String representation of its name. However, I
> want to create the object with parameters in its
> constructor. I'd rather do this a different way, but
> the architect's questionable love for reflection is
> forcing me to do otherwise.
If all you have is the classname as a string, you have little choice but to use reflection. But is that actually the case?
> The previous architect went hogwild with reflection
He wasn't the ******* that designed Spring, was he?
> > The previous architect went hogwild with
> reflection
>
> He wasn't the ******* that designed Spring, was he?
Screw you hippie, Spring rawks!
> > > The previous architect went hogwild with reflection
> >
> > He wasn't the ******* that designed Spring, was he?
>
> Screw you hippie, Spring rawks!
See you in hell, reflection boi!
> > > > The previous architect went hogwild with
> reflection
> >
> > He wasn't the ******* that designed Spring, was
>he?
>
> > Screw you hippie, Spring rawks!
>
> See you in hell, reflection boi!
I doubt it. I'm going to sneakily call setAccessible(true) on Heaven
> > > > > The previous architect went hogwild with reflection
> > >
> > > He wasn't the ******* that designed Spring, was he?
> >
> > > Screw you hippie, Spring rawks!
> >
> > See you in hell, reflection boi!
>
> I doubt it. I'm going to sneakily call setAccessible(true) on Heaven
The Devil is my SecurityManager :-(
At least I won't be going to the level reserved for applet coders...
> > > > > > The previous architect went hogwild with
> reflection
> > > >
> > > > He wasn't the ******* that designed Spring, was
> he?
> >
> > > Screw you hippie, Spring rawks!
> >
> > See you in hell, reflection boi!
>
> I doubt it. I'm going to sneakily call
> setAccessible(true) on Heaven
>
> The Devil is my SecurityManager :-(
> At least I won't be going to the level reserved for
> applet coders...
Old Nick certainly is busy these days, what with that, owning all the best tunes and, apparently, writing Eclipse