Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

In a constructor: pass 1 of its 'non final' args to a private method ?

Status
Not open for further replies.

cbweb2

Programmer
Sep 17, 2005
11
FR
Hi all,

I've to modify an existing Java application and I'm a bit lost ...
Actually one public class manages 2 tables and one of its methods calls the constructor of another public class and passes those tables as parameters.
The constructor of this second public class does several things and among all its actions it calls a private method and needs to pass those tables as parameters .. But I get an error saying "local variable xxx is accessed within inner class; needs to be declared final". But I don't want to declare them 'final' since they may be modified within the private method (some rows can be removed from the tables on certain conditions).
How can I do ?
Thx in advance !


 
The message says that you have inner classes (classes declared inside another class) but you don't specify it in your post.

Can you post more details about that inner classes? A code snippet would also help.

Cheers,
Dian
 
Yes, you have to make the table variable final IF you want to keep it as a local variable.

If you move the table variable xxx to be a class variable rather than a local one, you should no longer get the message.
 
I don't think you can state that without lookig at the code, maybe just passing the variable as argument can do the trick.

Cheers,
Dian
 
Hi Dian and idarke,

Thanks for your prompt replies. Actually I've found what was wrong and it was much more due to the fact I'm used to developping in C++ and wanted to implement things like in C++ .... One problem is now solved and I have to read tutorials now to be able to manage graphical interfaces (having rows displayed in bold, in colours, etc ...)

Cheers,

cbweb2
 
Glad you got it working.

You hace nice tutorials at java.sun.com

Cheers,
Dian
 
Thx Dian for this link !
Cheers,

cbweb2
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top