2017-07-19 5 views

答えて

4

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) 
+0

おかげで、それは私が欠けていたものです。 – gurghet

関連する問題