What is the Java equivalent of this Scala code?

What is the Java equivalent of these features 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 pass to the sign of Strategy :

 public interface Strategy<V extends Visitor<?, ?, ?>, X, Y> { } 

I am trying to translate the Visitor attribute into:

 public interface Visitor<X, S extends Strategy<?,?, ?>, R ?????> { } 

As you can see, I do not know how to understand / translate type R in Visitor . What is a similar Java equivalent?

+5
source share
1 answer

I am sure that it is impossible to write an equivalent in Java, its type system is not complex enough. R[v <: Visitor] is a more generic generic type, and this would require the following:

 interface Visitor<X, S extends Strategy<?, ?, ?>, R<? extends Visitor<?, ?, ?>> extends ...> 

but this cannot be expressed in Java because it does not have higher types in generics. And this is not even a mention of the fact that the bit (S{type X = Visitor.this.X;type V=v})#Y , which is a structural type with a refinement (as far as I remember, it is called that). I do not know a language other than Scala, which has such a thing.

+2
source

All Articles