Guest User

Untitled

a guest
Jun 21st, 2018
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. trait Longable{ def toLong(): Long }
  2.  
  3. implicit class IntCanLong(int: Int) extends Longable {
  4. def toLong(): Long = int.toLong
  5. }
  6.  
  7. implicit class StringCanLong(str: String) extends Longable {
  8. def toLong(): Long = str.toInt.toLong
  9. }
  10.  
  11. val l: List[Longable] = List(1,"5")
  12.  
  13. val myMap = Map[String, Longable](
  14. "one" -> 1,
  15. "two" -> "2"
  16. )
  17.  
  18. myMap.valuesIterator.foreach(l => println(l.toLong))
Add Comment
Please, Sign In to add comment