The Kotlin documentation itself states the following:
If an inline function has no inlinable function parameters and no reified type parameters, the compiler will issue a warning, since inlining such functions is very unlikely to be beneficial.
Both statements, no inlinable function parameters and no reified type parameters, are true for, for example, the following extension methods in String.kt
:
public inline fun String.reversed(): String
public inline fun String.slice(indices: Iterable<Int>) : String
public inline fun CharSequence.random(): Char
Can anyone explain me a specific reason why the language designers probably made the decisions to mark these methods as inline? Thanks.
As @somethingsomething pointed out in the comments, this question has been answered in a similar question before.
The answer there (by a JetBrains employee) was:
This particular function and a few others in kotlin-stdlib are marked as
@InlineOnly
so that they are not present in the actual stdlib class files and are only available for the Kotlin compiler to inline them. The goal that is achieved in this way is reducing the methods count in the artifacts, which matters for Android.
The @InlineOnly
annotation is also discussed in this question.