0

I have searched for hours, but I did not found a solution:

I want to implement a Scala class that extends a Java class that has different constructors:

The Java class (JGoodies):

public abstract class AbstractTableAdapter<E> 
    extends AbstractTableModel implements ListModelBindable

The constructors:

AbstractTableAdapter()
AbstractTableAdapter(ListModel listModel)
AbstractTableAdapter(String... columnNames)
AbstractTableAdapter(ListModel listModel, String... columnNames)

The ListModel is a generic interface if that matters:

public interface ListModel<E>

I tried in Scala 2.11:

class LibraryListTableModel(listModel: SelectionInList[Book], columnNames: Array[String]) extends AbstractTableAdapter[Book](listModel, columnNames) {
    def this() = this(null, null)
    def this(listModel: SelectionInList[Book]) = this(null, null)
    def this(columnNames: Array[String]) = this(null, null)
}

but that gives this error message:

error: overloaded method constructor AbstractTableAdapter with alternatives:
[INFO]   (x$1: javax.swing.ListModel[_],x$2: String*)com.jgoodies.binding.adapter.AbstractTableAdapter[eu.eyan.idakonyvtar.model.Book] <and>
[INFO]   (x$1: String*)com.jgoodies.binding.adapter.AbstractTableAdapter[eu.eyan.idakonyvtar.model.Book]
[INFO]  cannot be applied to (com.jgoodies.binding.list.SelectionInList[eu.eyan.idakonyvtar.model.Book], Array[String])
[INFO]     extends AbstractTableAdapter[Book](listModel, columnNames) {
[INFO]             ^
[ERROR] one error found

I think the String... causes the problem.. Is it possible to extend such an abstract class? Thanks: András

2 Answers 2

3

You can destructure in the incoming array into its various elements for the vararg by using the : _* syntax, i.e.:

case class Base(strs: String*) {  }
class Sub(ary: Array[String]) extends Base(ary:_*) { }

EDIT: Note, that WrappedArray (the result of the vararg) extends ArrayLike but I don't believe it's an Array.

Sign up to request clarification or add additional context in comments.

Comments

0

The solution was indeed marking the String... parameter with :_*

class LibraryListTableModel(listModel: SelectionInList[Book], columnNames: String*) extends AbstractTableAdapter[Book](listModel, columnNames: _*) {...}

This post helped too: http://daily-scala.blogspot.de/2009/11/varargs.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.