(Answer) (Category) FAQ-O-Matic : (Category) General : (Category) Compiler : (Category) Javac VS JBuilder's bcj :
We have some code which builds OK with Sun's JDK 1.3 javac, but gives the following error message when built with JBuilder3: "cannot reference variable markerList before superclass constructor has been called". Will upgrading to JB4 solve this problem?
(Paragraphs culled from a long and confusing thread... This is believed to be correct compiler behavior on JB's part.)

Gillmer Derge writes:

When you define an inner class, the compiler adds a reference to the outer class object (usually called something like "this$0", use javap to see it). So when you refer to "markerList" what you're really saying is "this$0.markerList," and since "this$0" is an instance variable declared (implicitly) in this class, you're violating that rule. Now, I may be abusing the JLS by using that quote in a way in which Sun never intended, but I don't think it's clearly an abuse.

You might want to try using "Counter.this.markerList" just to see whether that puts you into a different set of compiler rules that don't cause the error message, but I doubt it will help.

The following quote from Section 8.8.5.1 of the Java Language Specification http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#229267 covers this issue.

An explicit constructor invocation statement in a constructor body may not refer to any instance variables or instance methods declared in this class or any superclass, or use this or super in any expression; otherwise, a compile-time error occurs.

For example, if the first constructor of ColoredPoint in the example above were changed to:

    ColoredPoint(int x, int y) {
      this(x, y, color);
    }

then a compile-time error would occur, because an instance variable cannot be used within a superclass constructor invocation.


2001-Sep-08 2:16pm gyles19@visi.com
[Append to This Answer]
2001-Sep-08 2:16pm
Previous: (Answer) super.getSuperclass() and getClass.getSuperclass() return different results! Code compiled with javac returns the same value, but code compiled with JBuilder does not!
Next: (Answer) Sun Document: Bugs Fixed in J2SDK 1.3.1
This document is: http://www.visi.com/~gyles19/cgi-bin/fom.cgi?file=277
[Search] [Appearance]
This is a Faq-O-Matic 2.709.
This FAQ administered by gyles19@visi.com.

Other JBuilder Links

Java Community
Java Tools
Code Central
JB OpenTools
Community
Recent
Threads
Borland Chat
Chat FAQ
Feature Matrices
3.0 |  3.5 |  4.0
5.0 |  6.0 |  7.0
Shop for
JBuilder
JBuilder
Downloads
and reg keys
Report Piracy
Online Manuals
4.0 |  5.0 |  6.0
7.0
Borland
DevSupport's
Bug/RFE Form

Quality Central Client
JB Patches &
Updates
JBuilder FAQs TIs
JBuilder
Newsgroups
Tamaracka's
News Archive
Mr. Haki's
JBuilder Machine
JGuru's
JBuilder FAQ
Sun's Bug
Parade
Netring Home - About - Privacy
The
JBuilder Netring Logo
The Borland JBuilder Netring by JBuilder FAQ-O-Matic
[ Join Now | List Sites | Random | << Prev | Next >> ]
[ Previous 5 Sites | Skip Previous | Skip Next | Next 5 Sites ]