0
私は引数としてWrites[Class.type]
を受け取り、渡したとき、実際に渡された引数はWrites[Class]
であり、コンパイルを拒否すると言います。`Writes [MyClass]`と `Writes [MyClass.type]`の違いは?
2つの違いは何ですか?
私は引数としてWrites[Class.type]
を受け取り、渡したとき、実際に渡された引数はWrites[Class]
であり、コンパイルを拒否すると言います。`Writes [MyClass]`と `Writes [MyClass.type]`の違いは?
2つの違いは何ですか?
Class
は、Class
と呼ばれるタイプを指します。 Class.type
は、Class
という名前のオブジェクトのタイプを指します。
は一例として、このコードを考えてみましょう:
class Foo {
val x = 42
}
object Foo {
val y = 23
}
def f(foo: Foo) {
println(foo.x)
// The next line wouldn't work because the Foo class does not have a member y:
// println(foo.y)
}
def g(foo: Foo.type) {
println(foo.y)
// The next line wouldn't work because the Foo object does not have a member x:
println(foo.x)
}
val foo1 = new Foo
val foo2 = new Foo
f(foo1)
f(foo2)
// Does not work because the object Foo is not an instance of the class Foo:
// f(Foo)
g(Foo)
// Does not work because g only accepts the object Foo:
// g(foo1)
おかげで、それは私が欠けていたものです。 – gurghet