What is the Java equivalent of these traits in Scala?
trait Visitor {
type X
type S<:Strategy
type R[v<:Visitor] = (S{type X = Visitor.this.X;type V=v})#Y
}
trait Strategy {
type V<:Visitor
type X
type Y
}
I translate the Strategy
trait to:
public interface Strategy<V extends Visitor<?, ?, ?>, X, Y> {
}
I try translating trait Visitor
to:
public interface Visitor<X, S extends Strategy<?,?, ?>, R ?????> {
}
As you can see, I don't know how to understand/translate type R
in the Visitor
trait. What is a similar Java equivalent?
I'm pretty sure that it is impossible to write an equivalent in Java, its type system is just not sophisticated enough. R[v <: Visitor]
is a higher-kinded generic type and it would require something along these lines:
interface Visitor<X, S extends Strategy<?, ?, ?>, R<? extends Visitor<?, ?, ?>> extends ...>
but this is not possible to express in Java because it does not have higher-kinded types in generics. And that's not even mentioning that (S{type X = Visitor.this.X;type V=v})#Y
bit which is a structural type with refinement (as far as I remember, it is called like this). I don't know any other language except Scala which has such thing.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments