動的オブジェクトを実装するだけです(2.10.0-M3を使用):
import language.dynamics
object D extends Dynamic {
def selectDynamic( field : String ) = Symbol( field )
}
以下は正常に動作し、期待どおりです
object DynamicTest extends App {
println( D.a )
}
印刷'a
しかし、私がこれを試してみると:
object DynamicTest extends App {
println( D.x )
}
厄介なエラーが発生します:
[error] DynProb.scala:7: type mismatch;
[error] found : D.type
[error] required: ?{val x: ?}
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error] both method any2Ensuring in object Predef of type [A](x: A)Ensuring[A]
[error] and method any2ArrowAssoc in object Predef of type [A](x: A)ArrowAssoc[A]
[error] are possible conversion functions from D.type to ?{val x: ?}
[error] println( D.x )
[error] ^
[error] one error found
xはなぜ特別なのですか?私は愚かなことをしていますか?