Yaklaşık sonrası ile trait B
(daha yazabiliriz senin amaç, sanırım ki, farklı bir bit)
trait B extends A {
type MyType <: BInner with AInner
}
Ve bu toplam mantıklı. B#MyType
tipi bir değer, BInner
veya AInner
olarak görülebilir.
zaten
Abstract
'un bir alt sınıfı olduğundan
Abstract
yinelemenize gerek yoktur. Bu tür bir bildirim için örtük olduğu için
override
yazmanız gerekmez. Bu yüzden soru
A#MyType
neden
AInner
olarak çalışmıyor?
Scala dilinin özellikleri, uçucu türleri hakkında ne diyor. spec tarafından bahsedilen
3.6 Volatile Types
Type volatility approximates the possibility that a type parameter or abstract type instance of a type does not have any non-null values. As explained in (§3.1), a value member of a volatile type cannot appear in a path. A type is volatile if it falls into one of four categories: A compound type T1 with ... with Tn {R } is volatile if one of the following two conditions hold. 1. One of T2, ..., Tn is a type parameter or abstract type, or 2. T1 is an abstract type and and either the refinement R or a type Tj for j > 1 contributes an abstract member to the compound type, or 3. one of T1, ..., Tn is a singleton type. Here, a type S contributes an abstract member to a type T if S contains an abstract member that is also a member of T . A refinement R contributes an abstract member to a type T if R contains an abstract declaration which is also a member of T . A type designator is volatile if it is an alias of a volatile type, or if it designates a type parameter or abstract type that has a volatile type as its upper bound. A singleton type p.type is volatile, if the underlying type of path p is volatile. An existential type T forSome {Q } is volatile if T is volatile.
Diğer önemli öğe soyut tip Burada üste hakkındadır:
Another restriction applies to abstract type members: An abstract type member with a volatile type (§3.6) as its upper bound may not override an abstract type member which does not have a volatile upper bound.
derleyici hatadır:
error: overriding type MyType in trait A with bounds <: AInner;
type MyType is a volatile type; cannot override a type with non-volatile upper bound
Bu spec ile tutarlıdır. BInner with A#MyType
uçucudur. Bundan önce MyType
, Any
olarak uçucu değildir.
madde scala tipi sisteminde bir tür eşsiz anlama sahip olmasıdır. Bir soyut tip, bir alt sınıfa deklare edilen bir tip olarak düşünülebilir.Bu nedenle, soyut olduğu zaman soyut bir türün değerlerini beyan etmekte sorun yoktur. Diğer yandan, BInner with A#MyType
gibi bir türümüz varsa, bu türün birkaç anlamı olabilir. Uçucu olarak adlandırılır ve MyType
soyut tipini örnekleyen alt sınıflar kadar çok türde olabileceğinden, bu türden boş olmayan bir değere sahip olma mantıklı değildir. Bazı şeyleri basitleştirmek için, Any
alt tipi olmayan (ve Any
alt türü olan uçucu) tip olarak bir uçucu tür düşünebiliriz. Bu nedenle derleyicinin bahsettiği bir çelişki var.
Böyle iç özellikleri için bu sayesinde elde edebilirsiniz
What I'm trying to achieve here(in trait B) is to further restrict the type MyType declared > in Abstract, so any value of type MyType must extend all the MyTypes in the mixin tree.
gibi ifade hedefinize, geri dönersek.
trait Abstract {
type MyType
}
trait B extends Abstract {
trait MyType {
def bMethod : Int
}
}
trait A extends B {
trait MyType extends super.MyType {
}
}
Peki umarım bu sizin aradığınız şeydir.
Ayrıca, uçucu olmayan tiplerde soyut yöntem üyeleri de yasaklanmıştır? – Blaisorblade