Java to Scala with multiple constructors

118 Views Asked by At

I have a Java class that I am trying to rewrite into Scala. It has 3 constructors that need to be available even though I am only using 1.

public class EntityNet extends EntityThrowable {

@SuppressWarnings("unused")
public EntityNet(World world) {
    super(world);
    renderDistanceWeight = 10.0D;
}

@SuppressWarnings("unused")
public EntityNet(World world, double x, double y, double z) {
    super(world, x, y, z);
    renderDistanceWeight = 10.0D;
}

public EntityNet(World world, EntityLivingBase shooter) {
    super(world, shooter);
    renderDistanceWeight = 10.0D;
}

Any suggestions or directions would be appreciated.

1

There are 1 best solutions below

0
On

scala has named arguments and default values for arguments. here's example:

class HashMap[K,V](initialCapacity:Int = 16, loadFactor:Float = 0.75f) {
}
// Uses the defaults
val m1 = new HashMap[String,Int]
// initialCapacity 20, default loadFactor
val m2= new HashMap[String,Int](20)
// overriding both
val m3 = new HashMap[String,Int](20,0.8f)
// override only the loadFactory via
// named arguments
val m4 = new HashMap[String,Int](loadFactor = 0.8f)

you can find more info here