wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Inline method in Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inline method in Java" Watch "Inline method in Java" New topic
Author

Inline method in Java

Harsha Hegde
Greenhorn

Joined: Jan 12, 2009
Posts: 17

I have a small method which is called many many times, I want make this method call efficient, how can I do it?
There is something called inline method in C++ which actually does execution of small methods fast.
Thanks,
HH
Treimin Clark
Ranch Hand

Joined: Nov 12, 2008
Posts: 757
Harsha Hegde wrote:
There is something called inline method in C++ which actually does execution of small methods fast.


Please tell us that how it works on C++, efficiently. So we can show you a related feature in Java.
Sunil Kumar
Ranch Hand

Joined: Apr 24, 2007
Posts: 76
There is no concept of inline functions in java. Better say , it is implicit. The JVM automatically inlines the frequently used appropriate methods which it assumes would save time


Sunil Kumar
http://goodtoknowit.blogspot.com/
Harsha Hegde
Greenhorn

Joined: Jan 12, 2009
Posts: 17

Please tell us that how it works on C++, efficiently. So we can show you a related feature in Java

If a method is declared inline then during compile it get replaced by the actual code, no method call, so it is faster than calling a function.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39044
    
  23
Agree with Sunil Kumar.

You're not writing C++ but Java. It is completely different. There is a JVM which monitors the performance of your code, and can effectively optimise the code as it runs. It can alter the code; if there are frequent method calls which are acting as a drag on the system, then the JVM can alter the code with the calls inlined, if it "thinks" that will improve performance. That is what is called "just-in-time" compilation. It is usually counter-productive to try telling the JVM how to execute the code; it does it far better if left to itself than if the programmer tries to micro-manage code with keywords like "register" or "inline."
 
 
subject: Inline method in Java