In Java is there a performance difference between referencing a field through getter versus through a variable?

后端 未结 9 1330
失恋的感觉
失恋的感觉 2020-12-20 17:49

Is there any differences between doing

Field field = something.getSomethingElse().getField();
if (field == 0) {
//do something    
}
somelist.add(field);
         


        
9条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 18:33

    I wouldn't worry about the performance difference. You'd be better to not think about it and instead spend time on profiling your code in a realistic scenario. You will most likely find that the slow parts of your program aren't where you think they are.

提交回复
热议问题