Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Again forward references

 
Ruslan Spivak
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a question again about following code:
1)
class NoCompile {
static {
x = 100;
}
static int x;
{
j = 200;
}
int j;
}
2)
class Compile {
static {
Compile.x = 100;
}
static int x;
{
this.j = 200;
}
int j;
}
Why 1) doesn't compile while 2) compiles? What is the difference?
java langspec-2.0 declares that 1) compiles but it does not and I have to write as in 2) to gain a successful compile.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you talking about JLS 8.3.2 ? Because if it is the case, I think the section explains very weel what's going on during initialization. The diffrerence between the code 1 and 2 is also explained in 8.3.2.1 and 8.3.2.2
HIH
------------------
Valentin Crettaz
Sun Certified Programmer for Java 2 Platform
 
Nain Hwu
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ruslan,
This is a known bug. SUN has not fixed it yet. http://developer.java.sun.com/developer/bugParade/bugs/4459133.html
 
Malar Ravi
Ranch Hand
Posts: 51
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Valentin, according to the example given in JLS 8.3.2.3 this code should complie. But it says illegal forward reference when compiled.

 
Nain Hwu
Ranch Hand
Posts: 139
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Malar,
This is a known SDK bug. Please see my previous post.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic