# Using @inline with multiple dispatch

**URL:** <https://discourse.julialang.org/t/using-inline-with-multiple-dispatch/5718>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 5, 2017, 2:43am UTC](https://discourse.julialang.org/t/using-inline-with-multiple-dispatch/5718 "2017-09-05T02:43:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mcovalt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcovalt/32/1722_2.png) [@mcovalt](https://discourse.julialang.org/u/mcovalt)\
**Post date:** [September 5, 2017, 2:43am UTC](https://discourse.julialang.org/t/using-inline-with-multiple-dispatch/5718/1 "2017-09-05T02:43:25Z")

</div>

Just curious, what would the behavior of using `@inline` be when applied to two functions named the same, but operating differently based on types?

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 5, 2017, 8:26am UTC](https://discourse.julialang.org/t/using-inline-with-multiple-dispatch/5718/2 "2017-09-05T08:26:14Z")

</div>

What `@inplace` macro are you referring to? Is it in a package? Or do you mean `@inline`?

---

<div class="post-metadata">

**Author:** ![mcovalt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcovalt/32/1722_2.png) [@mcovalt](https://discourse.julialang.org/u/mcovalt)\
**Post date:** [September 5, 2017, 8:48am UTC](https://discourse.julialang.org/t/using-inline-with-multiple-dispatch/5718/3 "2017-09-05T08:48:22Z")

</div>

Oops, I mean `@inline`. Updated post.

---

<div class="post-metadata">

**Author:** ![mauro3](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mauro3/32/292_2.png) [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Post date:** [September 5, 2017, 9:07am UTC](https://discourse.julialang.org/t/using-inline-with-multiple-dispatch/5718/4 "2017-09-05T09:07:54Z")

</div>

Ok: `@inline` will force inlining to occur, whereas otherwise inlining may occur anyway (usually for short functions). The semantics are the same for inlined vs not inlined functions. Roughly: first a method is selected (multiple dispatch), then it is compiled for the specific argument types, and if inlined, the code is directly pasted at the appropriate place inside the other function, otherwise it is called via a jump.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [September 5, 2017, 9:08am UTC](https://discourse.julialang.org/t/using-inline-with-multiple-dispatch/5718/5 "2017-09-05T09:08:19Z")

</div>

Each gets inlined properly. Try a little demo for yourself and you’ll see. If this didn’t work, multiple dispatch would be incompatible with building efficient code.

The JIT compiler runs only after the input types are known, so there’s no _conceptual_ difficulty in how you go about doing this.
