What is the @InlineOnly annotation?

2019-06-21 05:43发布

问题:

I often see the @InlineOnly annotation when browsing Kotlin's stdlib. As far as I recall the annotation only happens to be on inline functions. What is the purpose of this annotation? Isn't it obvious that inline functions are always inlined? It's documentation isn't really helpful

Specifies that this function should not be called directly without inlining

Is it possible for inline functions to be called not inline?

回答1:

To quote an answer found here:

InlineOnly means that the Java method corresponding to this Kotlin function is marked private so that Java code can not access it (which is the only way to call an inline function without actually inlining it).

This annotation is internal only because

This annotation was added in the last moment before release, so we hadn't time to validate the design and decided to keep it internal for a while. There are good chances we make it public later.



标签: kotlin