KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have written a little snippet of code to test the Dynamic trait capabilities: class Foo extends Dynamic { def selectDynamic(name: String) { println("selectDynamic: " + name) } def applyDynamic(name: String)(args: Any*) { println("applyDynamic: " + name) } def applyDynamicNamed(name: String)(args: (String, Any)*) { println("applyDynamicNamed: " + name) } def updateDynamic(name: String)(value: Any) { println("updateDynamic: " + name) } } object Test { def main(args: Array[String]) { val foo = new Foo foo.bar(5) //1 foo.bar(x = 5) //2 foo.bar //3 foo.baz = 5 //4 } } The problem is that it wouldn't compile both in Scala 2.9 and 2.10 because of the fourth line in main : error: reassignment to val foo.baz = 5 If I comment this string, 2.9 would complain about the second line: error: not found: value x foo.bar(x = 5) Meanwhile 2.10 would compile and the program would produce: applyDynamic: bar applyDynamicNamed: bar selectDynamic: bar So now I wonder if I'm doing something wrong (maybe miss some dependencies)? Is there a difference between Dynamic's in Scala 2.9 and 2.10? And what's wrong with the foo.baz = 5 ?
Tags (comma-separated)
Save Edits
Cancel