| Author |
A question on nested functions
|
Stephen Davies
Ranch Hand
Joined: Jul 23, 2008
Posts: 352
|
|
I am a Java developer, learning Scala and I have just begun to look into nested functions. Whilst I understand the concept, I am still confused as to how they actually work in the code. Take my following example:
When I run this, I get no output whatsoever. Shouldn't the String I pass to the top method call be processed by both functions, and hence print out? Am I missing the bigger picture here?
|
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2693
|
|
You have declared the private function- lg(). But you need to invoke it to get executed.
|
Mohamed Sanaulla | My Blog
|
 |
Stephen Davies
Ranch Hand
Joined: Jul 23, 2008
Posts: 352
|
|
mohamed sanaullah wrote:You have declared the private function- lg(). But you need to invoke it to get executed.
It works now, many thanks. I can grasp the need to provide a call to lg, though when you say it is a private function I am confused. I'ts a local function object to the outer function, and despite being inaccessible to outside code (as in java) does this make it private as in the meaning of the access modifier? , I was under the impression that non declared access is public by default in Scala. unless otherwise declared. Hence, getMyName is public and that lg() is a local variable to it (within the inner scope only) and is simply implicitly inaccessible to code outside the getMyName function but not "private" as I have not declared it expressly so.
My question is more semantics than anything else, but I would like to clarify the situation.
|
 |
Mohamed Sanaulla
Bartender
Joined: Sep 08, 2007
Posts: 2693
|
|
Sorry for wrong usage of terms By private I meant- Local to that function- Scope limited to that function. Something like local variables.
|
 |
 |
|
|
subject: A question on nested functions
|
|
|