• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Inline method in Java

 
Greenhorn
Posts: 17
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 757
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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."
 
reply
    Bookmark Topic Watch Topic
  • New Topic