Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inline method

 
aakash bhatt
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is an inline method and when do we do that
Regards,
aakash
 
Peter Kristensson
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya!
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.
/Peter
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic