Created
December 27, 2011 14:07
-
-
Save lshoo/1523758 to your computer and use it in GitHub Desktop.
隐式转换注意隐式参数顺序问题
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 ch21 | |
class PreferredPrompt(val preference: String) | |
object JoesPrefs { | |
implicit val prompt = new PreferredPrompt("Yes, master> ") | |
} | |
object Greeter { | |
def greet(name: String)(implicit prompt: PreferredPrompt) { | |
println("Welcome, " + name + ". The system is readey") | |
println(prompt.preference) | |
} | |
def main(args: Array[String]): Unit = { | |
import JoesPrefs._ | |
//implicit val bobsPrompt = new PreferredPrompt("relax> ") | |
greet("Joe") | |
} | |
} | |
如果把object JoesPrefs放到object Greeter之后,就会出错. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment