Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal Forward Reference - compiler not consistent with JLS - Help

 
R Arun
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the JLS:

8.3.2.3 Restrictions on the use of Fields during Initialization
The declaration of a member needs to appear before it is used only if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold:
The usage occurs in an instance (respectively static) variable initializer of C or in an instance (respectively static) initializer of C.
The usage is not on the left hand side of an assignment.
C is the innermost class or interface enclosing the usage.
A compile-time error occurs if any of the three requirements above are not met.

However the following code does not compile using Sun's javac compiler (1.4.0):

In fact there is a specific example in the JLS that shows the above code to be legal - see the first line of the static intializer in the section referenced above where x = 10; is used before x is declared.
What's happening?
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a bug in javac. It doesn't follow JLS 8.3.2.3 There was a post in the Ranch showing a bug in the Database at SUN. You can search here or going directly to the database to see it.
 
R Arun
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jose.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic