Skip to content

Instantly share code, notes, and snippets.

@kijuky
Created August 16, 2011 10:56
Show Gist options
  • Save kijuky/1148846 to your computer and use it in GitHub Desktop.
Save kijuky/1148846 to your computer and use it in GitHub Desktop.
package object p {
implicit def richString(str: String) = new RichString(str)
def m(str: String) = {
println(str)
}
def m(str1: String, str2: String) = {
println(str1 + "," + str2)
}
}
package p
class RichString(str: String) {
def test = {
m(str)
}
}
// 追記
// RichString をどこか別のパッケージ(たとえば p2)にして
// import p._ とすると、コンパイルできます。
import p._
object Sample extends Application {
"Hello World".test
}
// > scalac Sample.scala package.scala RichString.scala
// RichString.scala:5: error: not enough arguments for method m: (str1: String,str2: String)Unit.
// Unspecified value parameter str2.
// m(str)
// ^
// one error found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment