Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inline method in Java

 
Harsha Hegde
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 757
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Harsha Hegde
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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."
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic