In Java 1.6.0_21, the first example below compiles fine, and I think that since parameter type restrictions are bare. That is, in the βZ extends Zenβ section below, Java resolves Zen for the slide as the name of a raw, non-generic type (the equivalent of the runtime is βerasedβ, type). It may be wrong and bad, but it can also be useful or at least stupid good times on a bus home:
public class CorefTest { public static interface Tao<Z extends Zen> { } public static interface Zen<T extends Tao> { } }
In Scala 2.8.0.final, below is compiled through CleanOceanWithFish, showing some basic types of param connections. But when we get to Zen and Tao, being common types interdependent, the Scala compiler rejects my weaving structure. See compiler errors in the comments.
package heaven.piece class Lucky { trait Water {} trait CleanWater extends Water {} trait Sea [W <: Water] {} trait Fish[S <: Sea[CleanWater]] {} trait CleanOceanWithFish[F <: Fish[CleanOceanWithFish[F]]] extends Sea[CleanWater]{}
So, how can I properly bind the Scala node (2.8.0) between Tao and Zen?
This is certainly a contrived example, but I really want to use Scala to extend some real Java types that I work in the above form (which existential types through "forSome" and "[_]" don't help me yet. I think getting Zen and Tao compilation in Scala is likely to show the way to this Java extension. If you can consider the Java extension problem in your answer, so much the better. Thanks for any help!
Update , published after the very useful first two answers below from Nikita S. and Chris N.
I have empirically learned about various Java + Scala scripting scenarios. The result is that when we want to have compatible coreferent types in both Java and Scala, then this Java construct:
public static interface JavaFunTao<JFZ extends JavaFunZen<? extends JavaFunTao<JFZ>>> { public JFZ consider(JFZ someZen, JavaFunTao<JFZ> otherTao); } public static interface JavaFunZen<JFT extends JavaFunTao<? extends JavaFunZen<JFT>>> { public JFT meditate(JFT someTao, JavaFunZen<JFT> otherZen); }
provides a more specific typification than my first Java example at the top (avoiding raw types), and then extends correctly in Scala as follows:
class HiFunTao[HFZ <: HiFunZen[ _ <: HiFunTao [HFZ]]] extends JavaFunTao[ HFZ] { override def consider(someZen: HFZ, otherTao: JavaFunTao[HFZ]) : HFZ = { println (this.toString() + " is considering " + someZen + " and " + otherTao); someZen } } class HiFunZen[HFT <: HiFunTao[ _ <: HiFunZen [HFT]]] extends JavaFunZen[ HFT] { override def meditate(someTao: HFT, otherZen: JavaFunZen[HFT]) : HFT = { println (this.toString() + " is meditating on " + someTao + " and " + otherZen); someTao } }
I checked that we can create simple concrete types based on them, create them and refer to their methods. The key step in Java and Scala is to place a restricted template at the point where the type parameter tree returns to the current declaration type, that is, "? Extends" in java and "_ <:" in Scala.