开发者

type definition in a package object "hijacking" the inheritance of a java class in scala code

I have the following situation:

I have a Java class hierarchy like this:

package org.foo.some;
public class Model extends org.foo.some.GenericModel { // ... }

package org.bar;
public class MyModel extends org.foo.some.Model { // ... }

where org.foo.some.Model and org.foo.some.GenericModel are out of my reach (not my code). In Scala, also out of my reach, there is:

package org {
  package foo {
    package object some {
      type Model = org.foo.some.ScalaModel
    }
  }
}

This leads to a funny behavior in Scala code, e.g.

val javaModel:MyModel = new org.bar.MyModel()

trait FooTrait[T <: org.foo.some.GenericModel] { // ... }

class FooClass extends FooTrait[MyModel] { //... }

does not compile and raises the following error:

type arguments [org.bar.MyModel] do not conform to trait FooTrait's type parameter bounds [T <: org.foo.some.GenericModel]

Further, I can't invoke any method of org.foo.some.Model n开发者_开发问答or of org.foo.some.GenericModel on javaModel:

javaModel.doSomething()

raises

value create is not a member of org.bar.MyModel

I am under the impression that the package object is "hijacking" the visibility of the Java class hierarchy in Scala code. Indeed, ScalaModel does not extend org.foo.some.GenericModel.

Is there maybe a way to still access the hierarchy from within Scala code?

Edit: when re-compiling the code out of my reach and removing the type re-definition, everything works. So I think what I'm looking at is a way to "disable" an package-level type definition for a specific class.


Are you using a GUI (in particular Eclipse) to build your project?

This seems related to Scala trouble accessing Java methods (that has no answer but where the general consensus is that the problem is not with scala but with Eclipse).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜