Overloading on return type ???
Posted
by Green Hyena
on Stack Overflow
See other posts from Stack Overflow
or by Green Hyena
Published on 2010-05-02T08:31:51Z
Indexed on
2010/05/02
8:37 UTC
Read the original article
Hit count: 178
scala
scala> val shares = Map("Apple" -> 23, "MicroSoft" -> 50, "IBM" -> 17)
shares: scala.collection.immutable.Map[java.lang.String,Int]
= Map(Apple -> 23, MicroSoft -> 50, IBM -> 17)
scala> val shareholders = shares map {_._1}
shareholders: scala.collection.immutable.Iterable[java.lang.String]
= List(Apple, MicroSoft, IBM)
scala> val newShares = shares map {case(k, v) => (k, 1.5 * v)}
newShares: scala.collection.immutable.Map[java.lang.String,Double]
= Map(Apple -> 34.5, MicroSoft -> 75.0, IBM -> 25.5)
From this example it seems like the map
method is overloaded on return type. Overloading on return type is not possible right? Would somebody please explain what's going on here?
© Stack Overflow or respective owner