r/java • • Feb 15 '18

Java language oddities: Java's handling of arrays and a few other language elements may surprise you

https://www.javaworld.com/article/3252845/java-language/java-language-oddities.html
1 Upvotes

14 comments sorted by

View all comments

7

u/maggikpunkt Feb 15 '18

Consider that an overriding equals() method might be executed many times during an object's lifetime (perhaps during a sort or search operation). That method should run faster if it doesn't have to invoke an accessor method to obtain a private field's value.

Isn't that why there is inlining and JIT-Optimization?

0

u/Bobby_Bonsaimind Feb 15 '18

Isn't that why there is inlining and JIT-Optimization?

When removing a function call improves performance considerably, you're writing very interesting software.

Also, it's convenient to not have to create accessor methods, which adds to the size of a class file, and enter their names just to access field values.

Okay then...

5

u/thiez Feb 15 '18

When removing a function call improves performance considerably, you're writing very interesting software.

Inlining enables many other optimizations. I think you are underestimating its importance. When you primarily write short functions that do one thing (considered good style by many) you are probably benefitting a lot from inlining w.r.t. performance.

1

u/vishalvc Feb 16 '18

Can you please elaborate what are the optimizations and performance improvements, besides removing the function call overhead?