If you inline a method, is only the method inlined...
# getting-started
b
If you inline a method, is only the method inlined or do you duplicate the entire class as well?
✅ 1
y
Depends what you mean by "the entire class" It'll inline the entire method body, including any anonymous `object`s and any local `class`es. That's why you can write something like:
Copy code
inline fun <reified T> foo() = object: Foo { fun foo(x: Any): Boolean = x is T }
Depending on your build setup, minifiers like R8 can recognize and deduplicate these extra classes
b
thank you
❤️ 1
y
FWIW, you can use "Show Kotlin Bytecode" in the IDE, or you can use Compiler Explorer
Wait I might be wrong; it's showing a deduplicated class somehow
It gets duplicated if there's
reified
magic going on
b
thank you
so tl;dr: might be better to move out reified inline methods into separate functions if possible
y
Well are you defining classes/anonymous objects inside the function? If not you'll be fine
b
I don't, I see
y
The outer class is not involved, to be clear, so that part is fine. In general, I tend to keep
inline
methods short and extract any big logic parts into helpers For library development, it's important since
inline
method bodies will be inlined for your consumers, so changing the bodies in a new version won't change the behaviour for already compiled code.
➕ 1