Possible Duplicate:
What does “outer =>” really mean?
When i look in to the source code of: scala/src/library/scala/Option.scala
sealed abstract class Option[+A] extends Product with Serializable {
self =>
I wander what the self use for. I know the normal use of self type is to restrict the class the trait can be mixed in. such as:
scala> trait A
defined trait A
scala> trait NeedA {self: A =>}
defined trait NeedA
scala> new NeedA {}
<console>:10: error: illegal inheritance;
self-type java.lang.Object with NeedA does not conform to NeedA's selftype NeedA with A
new NeedA {}
^
scala> new NeedA with A {}
res39: java.lang.Object with NeedA with A = $anon$1@4d04a0e8
scala>
but the "this =>" is not the case. what indeed this "this =>" used for?
In Python, we use = operator to create a copy of an object. You may think that this creates a new object; it doesn't. It only creates a new variable that shares the reference of the original object.
The duplicated() function is used to indicate duplicate Series values. Duplicated values are indicated as True values in the resulting Series. Either all duplicates, all except the first or all except the last occurrence of duplicates can be indicated.
It creates an alias to this, which may be handy in inner classes (synonymous for OuterClass.this)
class A {self =>
...
class B {
// self is the enclosing A, synonymous for A.this
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With