2011-12-03 8 views
5

可能性の重複:example in scalatest siteから
What is the difference between scala self-types and trait subclasses?このキーワードを使用して継承しますか?

。私は本当に彼らが特色にいくつかのDEFSを割り当てようようにそれはそう、私の知る限り理解し

trait FunSuiteStackBehaviors { 
        this: FunSuite => //This line 
         def a() {} 
         def b() {} 
} 

class StackFunSuite extends FunSuite with FunSuiteStackBehaviors {} 

を理解していないある特定の事があります。しかし、this: FunSuite =>部分は何をしていますか?私はFunSuiteをextendの代わりに使用しようとしました。

trait FunSuiteStackBehaviors extends FunSuite { 
         def a() {} 
         def b() {} 
} 

class StackFunSuite extends FunSuite with FunSuiteStackBehaviors {} 

そして私はまだ同じ結果に終わります。彼らは同じことですか?

+0

自己タイプです。 http://stackoverflow.com/questions/1990948/what-is-the-difference-between-scala-self-types-and-trait-subclasses http://stackoverflow.com/questions/tagged/self-type – retronym

+0

Hmm 。私が検索しようとすると、それらの質問は出てこない。それを指摘してくれてありがとう。 –

答えて

0

this: FunSuite =>は、自己型注釈と呼ばれます。 "this"については何も特別なことはありません両方のスニペットは同等です。 Hereisその理論的根拠に関する議論。短い自己タイプのアノテーションでは、IS-Aの関係ではなく、compositionalの性質を示すのに役立ちます。

1

=> XXXXはセルフタイプの注釈と呼ばれますhttp://www.scala-lang.org/node/124 基本的には、指定したタイプの「this」(現在のオブジェクト)のタイプを指定しています。 「内部からのキャスト」の種類

関連する問題