File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Illegal forward reference

 
Faisal Ahmad
Ranch Hand
Posts: 355
Chrome Java Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into this partial code listing:

Thanks in adv.
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
Faisal Ahmad
Ranch Hand
Posts: 355
Chrome Java Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 355
Chrome Java Redhat
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry, look into this code now:

I can conclude that outer s is visible inside the method!
 
Henry Wong
author
Marshal
Pie
Posts: 20836
75
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic