Java optimizer and redundant array evaluation

This is a very basic problem about Java optimization

If you have a simple for loop, iterate over the array and use array at the head of the loop Length instead of evaluating it before, then you only do it once (which is what I almost always do):

for(int i=0; i<array.length;i++) { ... }

The statement can be optimized so that the JVM knows whether the array changes over the duration of the loop so that it does not reevaluate the array every time Length?

Solution

More importantly, unless the field is mutable, the JVM will make this assumption, whether it is true or not

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>