Created
July 16, 2012 13:18
-
-
Save masayuki038/3122668 to your computer and use it in GitHub Desktop.
Implicit conversion test in Scala.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package net.wrap_trap.scala.examples | |
| object ImplicitConversionTest { | |
| def main(args : Array[String]) : Unit = { | |
| val s1 : String = "Foo" | |
| val i : Int = s1 // compile error 'type mismatch; found : String required: Int' without string2Int | |
| System.out.println("i: " + i); | |
| } | |
| implicit def string2Int(str: String) : Int = { | |
| 1 | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment