java - Can I say "if class A is subclass of class B, type A must be subtype of type B"? -
i have understands relationship between subtype , subclass, i'm not sure if correct.
say in java or scala, if declare concrete classes or types:
class b class extends b if class a subclass of class b, type a must subtype of type b?
and also, if type a subtype of type b, class a subclass of class b? (assume a , b both classes)
but true if it's concrete class or types
higher-order classes/typesbut higher-order types, not true, right? say:
class a[+t] then type a[string] subtype of type a[object], a[string] not subclass of a[object], right?
almost yes in question - can describe a , b beingness subtypes when generic classes, explain below.
there 2 ways "a subclasses b" , "a subtypes b" may not equivalent:
1, traits/interfaces can part of inheritance hierarchy can't described classes, , hence can't part of subclassing relationship. can utilize "extends" express more general relationship, in a extends b.
2, generic classes aren't simple types, type constructors (i.e. higher-kinded types). with:
class b[t] class a[t] extends b[t] it right "a[t] subtypes b[t]" a[t] , b[t] aren't classes , can't have subclassing relationship. right "a subclasses b" , "a subtypes b", in case describing relationships between higher-kinded types.
note scala, unlike java, allows type parameters declared co- or contravariant. if have class c[-t, +u] , 2 types a , b , a subtypes b, c[b, a] subtypes c[a, b], there no subclassing relationship there.
java scala subclassing type-systems subtyping
No comments:
Post a Comment