File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
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: 1283

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: 15084

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
jQuery in Action, 3rd edition