1

I have a normal Java class BaseModel as below

@AllArgsConstructor
class BaseModel {
   private String id;
}

Now I want to extend this in scala case class. Below is giving error:

case class Employee(id: String, dept: String) extends BaseModel(id)

Error: too many arguments for constructor BaseModel: ()

EDIT1: I have also tried with explicit constructor as below:

class BaseModel {
   private String id;
   public BaseModel(String id) {
      this.id = id;
   }
}

Now with this, it throws an error at compile time value id needs override modifier. When I try to add override modifier, it is throwing a compile-time error in the Scala class.

case class Employee(override val id: String, dept: String) extends BaseModel(id)

The error is for id.

Pls help me how can I fix this?

5
  • 3
    Your class only has an empty constructor, that annotation generates another one somehow but Scala does not understand Java annotations. Commented Oct 21, 2020 at 17:22
  • 1
    Does Scala know about Lombok annotations? Commented Oct 21, 2020 at 17:22
  • Updated question with more information. Commented Oct 21, 2020 at 17:38
  • 3
    @Suman Weird. With your new BaseModel case class Employee(id: String, dept: String) extends BaseModel(id) should work. Try clean build. Commented Oct 21, 2020 at 17:40
  • 1
    stackoverflow.com/questions/11171631/… Commented Oct 21, 2020 at 18:18

0

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.