This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Illegal forward reference 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 "Illegal forward reference" Watch "Illegal forward reference" New topic
Author

Illegal forward reference

Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 346

Look into this partial code listing:

Thanks in adv.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18508
    
  40


private String s = s;//illegal forward reference error. What does it mean?


Well, it is an illegal forward reference because you are declaring a reference "s" and trying to initialize it to itself.


I am assuming that you wanted to initialize it to the "s" reference in the outer class? Which quite frankly may not be visible during this initialization.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 346

Thanks for your reply.
Well, I read that "a method-local inner class can access private or any other members of its enclosing class." Based on this statement, I was trying to access a "private String s" variable of outer class. Is the above statement wrong?
Faisal Ahmad
Ranch Hand

Joined: Aug 31, 2006
Posts: 346

Henry, look into this code now:

I can conclude that outer s is visible inside the method!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18508
    
  40

I can conclude that outer s is visible inside the method!


It is in the second example. But I was referring to your first example.

Henry
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Illegal forward reference
 
Similar Threads
static and instance variables
illegal Forward Reference...
String
Enum illegal forward reference (compiles in Java 5 but not Java 6)
Enum class using constants