【发布时间】:2020-08-27 17:28:51
【问题描述】:
我有两个班级Float2 && Double2
public final class Float2 {
public float width;
public float height;
public Float2 multiplyBy(float number) {
return new Float2(this.width * number, this.height * number);
}
}
public class Double2 {
public double width;
public double height;
}
我想将 multiplyBy 方法的结果转换为 Double2,这样最后我就没有 Float2 newRectangleSize = rectangleSize.multiplyBy(3.2f); 而是 Double2 newRectangleSize 作为乘法的结果。当然,我可以分别转换宽度和高度值,但我想知道 java 中是否有更优雅的解决方案?
【问题讨论】:
-
如果
Float2可以转换为Double2,Double2 newRectangleSize = (Double2) rectangleSize.multiplyBy(3.2f);将起作用。
标签: java casting floating-point double