Will the java compiler optimize the method call for the final static variable? And what happens when it becomes a dalwick code?

I have the following code

 float square(float val) { return val*val;}
 boolean isInCircle(final float x,final float y) {

        float squareDistance = square(cx - x) + square(cy - y);
        return squareDistance < square(RADIUS);
    }

where RADIUS- static final float.

Will the java compiler optimize the call square(RADIUS)?

What happens when this code is converted to dalvikfor android? Will it be optimized?

+5
source share
4 answers

Optimizations in Java are performed (as far as I know) by the HotSpot compiler at runtime (bytecode is optimized when switching to machine code), Thus, the answer is yes and no.

, JVM, . , JVM , , ( ). SHA1 Windows JVM Linux. , ( , Linux) 40% ...

, , HotSpot JVM, JVM...

+1

Java .

JVM HotSpot (RADIUS).

Android JVM.

square() , return (cx-x)*(cx-x)+(cy-y)*(cy-y) < RADIUS*RADIUS; /JVM . , -)

+3

Dalvik JIT , square(), (, , static). , , .

, !

+2

, , , , , "" , , , .

-1

All Articles