This week's book giveaway is in the OCAJP forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide 1Z0-808 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
The moose likes Java in General and the fly likes Inline function in JAVA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Inline function in JAVA" Watch "Inline function in JAVA" New topic

Inline function in JAVA

Kaustubh G Sharma
Ranch Hand

Joined: May 13, 2010
Posts: 1281

Hi .... Is there any option in java from where I can use the funcionality like of inline function as I used in c++?

No Kaustubh No Fun, Know Kaustubh Know Fun..
David Newton

Joined: Sep 29, 2008
Posts: 12617

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14487

In Java, there is no way to specify that you want a method to be inlined.

However, the JVM does inlining automatically for you. If you have for example a JavaBean class with simple getters, like this:

then the JVM will be smart enough to inline those getter methods at the places you call them. So calling those getter methods will be just as efficient as accessing the member variables directly.

In other words, normally you don't have to worry about inlining yourself in Java.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: Inline function in JAVA