Let's say I have a class
Box(double xi, double yi, double zi, double xf, double yf, double zf)
and I have a method
Box#collides(Box other){
if(other.xf < xi || other.xi > xf) return false;
if(other.yf < yi || other.yi > yf) return false;
return other.zf >= zi && other.zi <= zf;
}
I then get two boxes. I compare the first
Box(a,b,c,d,e,f)
with .collides()
to the other box,
Box(A,B,C,D,E,F)
Will the Box objects still be created? Or will the JVM be smart and use something similar to
static collides(double xi, double yi, double zi, double xf, double yf, double zf, double xi, double oyi, double ozi, double oxf, double oyf, double ozf){
if(oxf < xi || oxi > xf) return false;
if(oyf < yi || oyi > yf) return false;
return ozf >= zi && ozi <= zf;
}
This might seem like a micro-optimization, but in my case, potentially millions of Box
es are being instantiated.