Created
August 16, 2011 10:56
-
-
Save kijuky/1148846 to your computer and use it in GitHub Desktop.
This file contains 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 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) | |
} | |
} |
This file contains 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 p | |
class RichString(str: String) { | |
def test = { | |
m(str) | |
} | |
} | |
// 追記 | |
// RichString をどこか別のパッケージ(たとえば p2)にして | |
// import p._ とすると、コンパイルできます。 |
This file contains 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
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