Question about Constructors in Child Classes

I’m currently facing a problem that I need to extend a class from Java, whose constructors are like <init>#(Int) and <init>#(String) for different usages.

I need to create both of them in my Scala child classes, but as far as I know, Scala only allows for 1 primary constructor that can call super, others are forced to call the primary constructor.

I don’t know if I misunderstand it or in Scala there is a better way to handle this situation?

1 Like

AFAIK you are correct.
Thus, I think the best thing you can do is have two classes, each one called the right constructor, and hide them behind a factory.

In Scala, how can I subclass a Java class with multiple constructors?

Subclassing and overriding Java class with protected field access

2 Likes

Oh, I actually works. But this design it pretty weird imo.