scala - Implicit vals in traits behave differently with type annotation -


Just wondering whether the following is a bug or a feature:

  in the Scala version Welcome to 2.10.0-M3 (Java Hotspot (TM) 64-bit server VM, Java 1.7.0). Type them in the expression to evaluate them. Type: Support for more information> Scala & gt; Class Type Class [T] Defined Class Type Class Scale & gt; Attribute A [T] {| Inherent Values ​​T = vested [type class] [t]] | } & Lt; Console & gt;: 9: Error: The value for the parameter e could not be found: TypeClass [T] Built-in wall T = vested [TypeClass [T]] ^   

Expected as, Does not compile because there is no barrier to T but when I add a type of annotation it is compiled:

  scala> Attribute A [T] {| Built-in Val T: TypeClass [t] = Inquiry [Type Class [T]] | } Defined attribute A   

Should the compiler not complain here? Why should one type of annotation be different? If we do something quick with this feature, then t is null .

Actually, you're just doing yourself here. : -)

You have just announced that the contained is typeclass [t] is val t that is, val t = t , which makes it empty!

T is an abstract, so the compiler can not provide a TypeClass for it, you will need to get it from the T parameter , But you will not be able to attribute . In square , create it T: TypeClass .

Comments