Given that I have a Base class that has a single argument constructor with a TextBox as an argument. If I have a Simple class like this:
public class Simple extends Base { public Simple(){ TextBox t = new TextBox(); super(t);
I get an error message indicating that the super call should be the first call in the constructor. However, oddly enough, I can do this.
public class Simple extends Base { public Simple(){ super(new TextBox()); } }
Why is this allowed, but the first example is not? I can understand that you need to configure the subclass first and possibly not allow the creation of object variables before calling the superconstructor. But t is obviously a method (local) variable, so why not allow it?
Is there a way around this limitation? Is there a good and safe way to keep variables in things that you could create before calling super, but AFTER you entered the constructor? Or, more generally, allowing you to do the calculation before the super is actually called, but inside the constructor?
Thank.
java
Stephen Cagle Feb 20 '10 at 20:28 2010-02-20 20:28
source share