Skip to content

Instantly share code, notes, and snippets.

@masayuki038
Created July 16, 2012 13:18
Show Gist options
  • Save masayuki038/3122668 to your computer and use it in GitHub Desktop.
Save masayuki038/3122668 to your computer and use it in GitHub Desktop.
Implicit conversion test in Scala.
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