Re: What is shadowing

Angel Java Lopez <[email protected]>
Newsgroups gmane.comp.lang.scala
Message-ID <CAMs+Dq+5q3qFZna9CT3QHpUVeYycLYqfr4XZCGWXr_CxvL1yRA@mail.gmail.com>
The external x is not visible because THERE IS ANOTHER x, defined "inside"
a block, notice the second "val x = "

This second x hides the first one, in that block

val x = 0 // external

....  {
    val x = ... // internal to this block, shadows, hides the external x
}


Angel "Java" Lopez
@ajlopez



On Sun, Jun 21, 2015 at 6:09 PM, sebastian_cheung via scala-language <
[email protected]> wrote:

> Following Coursera and lecture example:
>
> Why f is visible from within definition of 'result' and x is not?
>
> Thanks
>
> val x = 0
>
> def f(y: Int) = y + 1
>
> val result = {
>   val x = f(3)  //f is externally defined
>   x * x   // but x is internally defined, shadows the occurrence of the outer x
> } + x
>
>  --
> You received this message because you are subscribed to the Google Groups
> "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.