0

我有一个 Java 类,我正在尝试将其重写为 Scala。它有 3 个构造函数需要可用,即使我只使用 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;
}

任何建议或指示将不胜感激。

4

1 回答 1

0

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

于 2016-02-13T18:35:59.690 回答