wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Again forward references Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Again forward references" Watch "Again forward references" New topic
Author

Again forward references

Ruslan Spivak
Greenhorn

Joined: Nov 28, 2001
Posts: 2
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

Joined: Aug 26, 2001
Posts: 7610
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


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
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

Joined: Oct 15, 2001
Posts: 51
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

Joined: Sep 16, 2001
Posts: 139
Malar,
This is a known SDK bug. Please see my previous post.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Again forward references
 
Similar Threads
About Block Initializer
Forward references
strange code from Jls about initialization of fields
Local Variables
Forward Referencing