Suzan Cioc
Suzan Cioc

Reputation: 30127

Does Java compiler eliminate function calls from getters?

Can I be sure that

private int value;
public int getValue() { return value; }

is compiled by compiler in the same way as

public int Value;

in the terms of number of instructions and execution time? I mean do modern compilers trying to make functions "inline" (c++ term)?

Upvotes: 0

Views: 569

Answers (1)

SLaks
SLaks

Reputation: 887797

No; the Java compiler will not change that.

However, the JITter probably will.

Upvotes: 4

Related Questions