below code snippet...a bit testing mode code snippet.i trying create method through can change return type.
while calling method getting exception "class type expected object found"
trait trait b extends { def aba[t](a:int):t } class d class c extends b { def aba[d](a:int) = { println("asasas") new d } }
the actual error in scala 2.11 is
:13: error: class type required d found
which means can't instantiate generic type d - d class shadowed [d] definition
you can't override t (as part of aba's method signature) due liskov substitution principle change behaviour (and signature) subclass. can define t type member:
trait trait b extends { type t def aba(a:int):t } class d class c extends b { type t = d def aba(a:int): t = { println("asasas") new d } }
Comments
Post a Comment