views:

53

answers:

2

I have multiple constructor in a Java class.

public class A{
  public A(){...}
  public A(String param){...}
  public A(String param, Object value}
}

Now I want to create a Scala class that inherit from that class

class B extends A{
  super("abc")
}

But this syntax is invalid. Scala is complaining that '.' expected but '(' found.

What is the valid way to do this?

+5  A: 

You have to append the constructor arguments to the class definition like this:

class B extends A("abc")
Moritz
+3  A: 

As Moritz says, you have to provide the constructor args directly in the class definition. Additionally you can use secondary constructors that way:

class B(a:String, b:String) extends A(a,b) {
  def this(a:String) = this(a, "some default")
  def this(num:Int) = this(num.toString)
}

But you must refer to this, super is not possible.

Landei