Using access methods inside within a class?

I am wondering if using class access methods in the class itself will cause performance issues. I am wondering about Java compilers specifically, but I suppose this is a somewhat linguistic agnostic.

+3
source share
4 answers

AFAIK, newer JVMs very well optimize bytecode on startup and on the fly.

The documentation from the J2SE SDK v 1.4.2 (which is already very old, for example, about a decade) already mentions that the JVM will embed access calls in the class:

" Java 2 Java VM . Java , , . , , , . inlining , . Java VM , . "( ) J2SE SDK 1.4.2_02 8 :

, , < , "", > . , , , , , , , , .

+2

" ", . -, . /, - . . Android Developers, , : getters/seters.

+1

, Java .

JIT , /, .

JVM , .

0

Accessors are usually not optimized (i.e., converted to a direct call to a class property), so you should avoid using them, since calling a method means finding a method in a virtual table: see http://www.wordiq.com/definition/Optimization_of_Java

-1
source

Source: https://habr.com/ru/post/1788668/


All Articles