Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ListView from Scala 2.9.2 with Java 7 gives compile error

I'm working on a project that use scala 2.9.2 and java 7.

What I'm trying to do is create a GUI using the scala ListView.

Here's a small code snippet:

private val listView = new ListView[Document](someList)
.
.
.
for (selectedDocument <- listView.peer.getSelectedValuesList) {
    doSomething(selectedDocument)
}

This gives me the following compile error:

error: something is wrong (wrong class file?): class JList with type parameters [E] gets applied to arguments [], phase = namer for (selectedDocument <- listView.peer.getSelectedValuesList) {

I'm guessing this is because in ListView, peer is defined without type parameter:

override lazy val peer: JList = new JList with SuperMixin

So the question is: is it impossible to use the ListView from scala-swing with Java 7?

like image 597
ulejon Avatar asked Nov 06 '12 14:11

ulejon


1 Answers

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!

like image 128
ulejon Avatar answered Nov 15 '22 04:11

ulejon