| Author |
inner anonymous class return object
|
Edward Chen
Ranch Hand
Joined: Dec 23, 2003
Posts: 758
|
|
In above coding, how could return oject to the outer class ? for example, "outerC" should be get the collection "students" . Thanks.
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24057
|
|
You can assign directly to the variable "outerC" if it's a member variable of the enclosing instance. If it's a local variable, then you need to do a trick of some kind, because inner classes can only access final local variables. One thing you could do would be to initialize outerC like this:\ final Collection outerC = new ArrayList(); and then in the inner class, say Collection students = DBFunctions.loadData(pb,productId,null,null); outerC.addAll(students);
|
[Jess in Action][AskingGoodQuestions]
|
 |
Ilja Preuss
author
Sheriff
Joined: Jul 11, 2001
Posts: 14112
|
|
Originally posted by Ernest Friedman-Hill: You can assign directly to the variable "outerC" if it's a member variable of the enclosing instance. If it's a local variable, then you need to do a trick of some kind, because inner classes can only access final local variables. One thing you could do would be to initialize outerC like this:\ final Collection outerC = new ArrayList(); and then in the inner class, say Collection students = DBFunctions.loadData(pb,productId,null,null); outerC.addAll(students);
In my humble opinion, such a solution is a dirty hack. I'd first like to know more about *why* you want to "return" the value, to evaluate better alternatives...
|
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
|
 |
 |
|
|
subject: inner anonymous class return object
|
|
|