Re: "call to super must be first statement in constructor"
From: Heiner Kücker (Mail_at_Heiner-Kuecker.de)
Date: 01/30/05
- Previous message: Paul Chapman: ""call to super must be first statement in constructor""
- In reply to: Paul Chapman: ""call to super must be first statement in constructor""
- Next in thread: Ryan Stewart: "Re: "call to super must be first statement in constructor""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 30 Jan 2005 15:09:22 +0100
Paul Chapman wrote
> Here is an example code fragment:
>
> abstract class Outer
> {
> protected abstract int getValue();
> protected final int value;
> Outer() {
> value = getValue(); }
> }
>
> class Subclass extends Outer
> {
> protected int getValue() {
> return valueProvider.getValue(); }
> private final SomeClass valueProvider;
> Subclass(SomeClass aValueProvider) {
> valueProvider = aValueProvider;
> super(); }
> }
>
> Attempting to compile something like this produces the error message in the
> subject line.
>
> Switching the two lines in the Subclass constructor obviously won't work.
>
> Using a separate initialize() method to initialize Outer means that
> Outer.value can't benefit from the security of being final.
>
> Is there a way out of this tangle?
The super() call must be the first statement in a
constructor of a child class.
If you no wriites the super() call,
Java called super() automatically.
Is this a problem for your program?
-- Heiner Kuecker Internet: http://www.heinerkuecker.de http://www.heiner-kuecker.de JSP WorkFlow PageFlow Page Flow FlowControl Navigation: http://www.control-and-command.de Java Expression Formula Parser: http://www.heinerkuecker.de/Expression.html CnC Template Technology http://www.heinerkuecker.de/Expression.html#templ Domain Specific Languages http://www.heinerkuecker.de/DomainParser.html
- Previous message: Paul Chapman: ""call to super must be first statement in constructor""
- In reply to: Paul Chapman: ""call to super must be first statement in constructor""
- Next in thread: Ryan Stewart: "Re: "call to super must be first statement in constructor""
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|