This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
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 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.