Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java public static final object

Tags:

java

static

final

following code, containing file is here

public abstract class Quart extends TweenEquation {
    public static final Quart IN = new Quart() {
        @Override
        public final float compute(float t) {
        return t*t*t*t;
    }
    ...

if i call Quart.IN.compute(0.5f) somewhere in my running application (e.g. in a render() function that is called 60 times per second), does this create a new Quart on every call, or is it just allocated once?

it would make sense, right?

thanks, cheers

like image 581
kampfgnu Avatar asked Dec 21 '25 12:12

kampfgnu


1 Answers

By definition, a final variable can only be assigned once. And static fields of a class are initialized when the class is loaded. So obviously, the IN Quart instance is created just once.

like image 63
JB Nizet Avatar answered Dec 23 '25 02:12

JB Nizet