File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Inline method 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" Watch "Inline method" New topic

Inline method

aakash bhatt
Ranch Hand

Joined: Jan 09, 2003
Posts: 182
What is an inline method and when do we do that
Peter Kristensson
Ranch Hand

Joined: Jul 02, 2001
Posts: 118
What is an inline method and when do we do that?
If I'm not completelty mistaken, inlining is a thing that's happening during compile-time. The compiler inserts the code for a method where the method itself is called. I think that this only happens when the called method is in the same class as the caller-method.
I'll try to make an example.
Consider this class:

Now this would be transformed to something like this during compile-time:

Not sure that it will be exactly this way, but the basiscs are ther I think.
Hope this helps.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140
Peter's explantion on inline method is correct.
But however, a method MAY be made inline if it is declared final.
I don't thing all the final methods will be made inline. It is upto the compiler to decide to make a final method inline or not.
Inline methods reduces the overheads on method calls.
I agree. Here's the link:
subject: Inline method
It's not a secret anymore!