问题
Can I use aliasing so I don't need to change either of the type parameter/member in the following name clash situation:
trait Bar {
type A
}
trait Foo {
def get[A]: Option[Bar { type A = A }] // "illegal cyclic reference"
}
I know I can write
trait Foo {
def get[A1]: Option[Bar { type A = A1 }]
}
But I would really prefer not to change the type name.
回答1:
You could e.g. do something like this:
trait Bar {
type A
}
trait Foo {
type M[X] = Bar { type A = X }
def get[A]: Option[M[A]]
}
Or inline:
def get[A]: Option[({ type X[Y] = Bar { type A = Y }})#X[A]] = ???
Or, if you prefer:
def get[A]: Option[({ type A1 = A; type X = Bar { type A = A1 }})#X] = ???
来源:https://stackoverflow.com/questions/16375857/type-aliasing-to-avoid-name-clash-in-type-refinement