# How to avoid boxing of inline class for function interface

**URL:** <https://discuss.kotlinlang.org/t/how-to-avoid-boxing-of-inline-class-for-function-interface/10051>\
**Category:** Language Design\
**Created:** [October 28, 2018, 10:58pm UTC](https://discuss.kotlinlang.org/t/how-to-avoid-boxing-of-inline-class-for-function-interface/10051 "2018-10-28T22:58:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Christoph](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.kotlinlang.org/christoph/32/2517_2.png) [@Christoph](https://discuss.kotlinlang.org/u/Christoph)\
**Post date:** [October 28, 2018, 10:58pm UTC](https://discuss.kotlinlang.org/t/how-to-avoid-boxing-of-inline-class-for-function-interface/10051/1 "2018-10-28T22:58:09Z")

</div>

I am trying to use inline classes in performance critical code and thus would like to avoid boxing.  
I understand the [documentation](https://kotlinlang.org/docs/reference/inline-classes.html#representation) states that when using a inline class in a generic type (`kotlin.Function<out R>` in my case) it will be boxed.  
E.g.:

```auto
inline class MyInt(val i: Int)

fun foo(i: MyInt, f: (MyInt) -> Unit) {
    f(i) // i is boxed
}

```

One way to get around this is to create a new function interface, e.g.

```auto
interface MyFun {
    operator fun invoke(i: MyInt)
}

fun foo2(i: MyInt, f: MyFun) {
    f(i) // i is not boxed
}

```

But this has other problems: Cannot use lambdas, cannot pass `kotlin.Function`s directly.

Is there another, more elegant solution to this?
