I have two classes 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;
}
I want to cast the result of multiplyBy method to a Double2 so that in the end I do not have Float2 newRectangleSize = rectangleSize.multiplyBy(3.2f); but Double2 newRectangleSize as the result of multiplication. Of course I can cast width and height values separately but I was wondering if there was a more ellegant solution in java?
Double2 newRectangleSize = (Double2) rectangleSize.multiplyBy(3.2f);would work ifFloat2could be cast toDouble2.