> -----Original Message----- > From: Thomas Dudziak [mailto:[EMAIL PROTECTED] > Sent: quarta-feira, 28 de Dezembro de 2005 15:23 > To: Jakarta Commons Users List > Subject: Re: [digester] instantiationException if using internal classes ? > > On 12/28/05, Diogo Quintela (EF) <[EMAIL PROTECTED]> wrote: > > > Non-static inner classes as in your example, despite having an empty > > constructor, are managed internally by java through a constructor with > an > > instance to containing class instance (as I believe), so it has direct > > access to the instance variables and methods of its enclosing instance. > > > > A brief lookout into reflection api, doesn't seem to be able to > instantiate > > this type of classes; as digester is trying to instantiate that class > though > > reflection you must have problems... > > Inner classes need an outer class instance for creation. If you for > instance have this class: > > public class A > { > public class B > { > ... > } > } > > then you can create an instance of B *outside* of A only with: > > A anInstanceOfA = ... > B anInstanceOfB = anInstanceOfA.new B(); > > If I remember correctly, reflection works similar. The inner class > won't have a no-arg constructor but instead every of its constructors > (even the default one supplied by Java if none is defined) > automatically gets an additional first parameter of the type of the > enclosing class. So accessing the constructor via reflection would be > something like: > > Constructor constructor = A.B.class.getDeclaredConstructor(new Class[] > { A.class}); > > anInstanceOfB = (A.B)constructor.new Instance(new Object[] { anInstanceOfA > });
You surely put it much cleaner than I did. In conclusion, if digester supports any kind of mechanism to define the constructors to be used (using values from the stack) Valerio can use inner classes at will. > > Tom > Diogo > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
