What is the Java equivalent of this Scala code?

Stuck

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?

Vladimir Matveev

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Equivalent Scala code for Java code

From Dev

What is the equivalent Scala code for this Imperative coding style?

From Dev

What is Scala's equivalent of java char[]?

From Dev

What is Scala's equivalent of java char[]?

From Dev

What is the equivalent of this snippet of Java code in C#?

From Dev

What is this Java code equivalent in C# ? (setRequestEntity)

From Dev

What is this Java code equivalent in C# ? (setRequestEntity)

From Dev

What is the Java-compatibile equivalent in Scala for <? extends Foo>

From Dev

Equivalent of Java '?' in Scala

From Dev

Equivalent to Java summaryStatistics in Scala

From Dev

What is the code equivalent to this css code?

From Java

What is the Java equivalent for LINQ?

From Dev

What is the 'defer' equivalent for Java

From Dev

What is the equivalent of :: operator in java?

From Dev

Is there an equivalent of Java's this in Scala constructors?

From Dev

Scala equivalent of Java's Number

From Dev

The java "Object" Class equivalent in Scala

From Dev

Is this Python code equivalent of Java code?

From Dev

What is the Scala equivalent of Clojure's Atom?

From Dev

What is the Scala case class equivalent in PySpark?

From Dev

What is the Scala equivalent to Clojure's threading macros?

From Dev

What is the Clojure equivalent of Scala's zipWithIndex?

From Dev

What is the Scala equivalent of Clojure's Atom?

From Dev

What is the best way to run a Java program that also has Scala code?

From Dev

What is the equivalent of javascript setTimeout in Java?

From Dev

What is the equivalent of stringByFoldingWithOptions:locale: in Java?

From Dev

Java 8: What is the equivalent of "UseSplitVerifier"?

From Dev

What is the equivalent of Java Object in Swift?

From Dev

What is the Python equivalent of RequestConfig in Java?

Related Related

  1. 1

    Equivalent Scala code for Java code

  2. 2

    What is the equivalent Scala code for this Imperative coding style?

  3. 3

    What is Scala's equivalent of java char[]?

  4. 4

    What is Scala's equivalent of java char[]?

  5. 5

    What is the equivalent of this snippet of Java code in C#?

  6. 6

    What is this Java code equivalent in C# ? (setRequestEntity)

  7. 7

    What is this Java code equivalent in C# ? (setRequestEntity)

  8. 8

    What is the Java-compatibile equivalent in Scala for <? extends Foo>

  9. 9

    Equivalent of Java '?' in Scala

  10. 10

    Equivalent to Java summaryStatistics in Scala

  11. 11

    What is the code equivalent to this css code?

  12. 12

    What is the Java equivalent for LINQ?

  13. 13

    What is the 'defer' equivalent for Java

  14. 14

    What is the equivalent of :: operator in java?

  15. 15

    Is there an equivalent of Java's this in Scala constructors?

  16. 16

    Scala equivalent of Java's Number

  17. 17

    The java "Object" Class equivalent in Scala

  18. 18

    Is this Python code equivalent of Java code?

  19. 19

    What is the Scala equivalent of Clojure's Atom?

  20. 20

    What is the Scala case class equivalent in PySpark?

  21. 21

    What is the Scala equivalent to Clojure's threading macros?

  22. 22

    What is the Clojure equivalent of Scala's zipWithIndex?

  23. 23

    What is the Scala equivalent of Clojure's Atom?

  24. 24

    What is the best way to run a Java program that also has Scala code?

  25. 25

    What is the equivalent of javascript setTimeout in Java?

  26. 26

    What is the equivalent of stringByFoldingWithOptions:locale: in Java?

  27. 27

    Java 8: What is the equivalent of "UseSplitVerifier"?

  28. 28

    What is the equivalent of Java Object in Swift?

  29. 29

    What is the Python equivalent of RequestConfig in Java?

HotTag

Archive