File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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: 355

Look into this partial code listing:

Thanks in adv.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 19070
    
  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: 355

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: 355

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: 19070
    
  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