Using ListView from Scala 2.9.2 with Java 7 gives compile error

不羁的心 提交于 2019-12-04 07:34:26

Solved this issue by extending Scala's ListView and adding a "typed peer".

class ExtendedListView[A: ClassManifest] extends ListView[A] {
    lazy val typedPeer: JList[A] = peer.asInstanceOf[JList[A]]

    def selectionEmpty = typedPeer.isSelectionEmpty

    // Other functions omitted
}

Works great!

The problem is that many swing components have been "generified" in Java 7, leading to incompatibilities. The scala library was certainly compiled toward a version of Java < 1.7. I would advise to compile your scala code against Java 1.6. You can still compile you Java code in Java 1.7 and use it from your scala code, and in additioncode compiled against Java 1.6 can run on a JVM 1.7.

UPDATE: someone stumbled against the same problem: http://comments.gmane.org/gmane.comp.lang.scala.debate/9158

I have written a small library SwingPlus which makes it possible to use a ListView both when compiling on Java 6 and Java 7+. The problem (as others have pointed out) is the generification of Swing in Java 7.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!