Calling a getter multiple times or calling once and assigning to a variable?

后端 未结 13 1695
无人共我
无人共我 2021-02-05 15:26

say suppose I have class as :

public class Age {

    private int age;

    public int getAge() {
       return this.age;
    }

}

In my Main c

13条回答
  •  日久生厌
    2021-02-05 16:01

    Don't bother. It's absolutely not worth micro-optimizing like this. Wait until you finish your code, then it runs too slowly, then get out a profiler and work on what the profiler tells you is the source of the problem.

    Premature optimization is the root of all evil.

提交回复
热议问题