Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the @InlineOnly annotation?

Tags:

kotlin

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?

like image 895
Mibac Avatar asked Aug 18 '17 18:08

Mibac


People also ask

What is inline C?

In an inline function, a function call is replaced by the actual program code. Most of the Inline functions are used for small computations. They are not suitable for large computing. An inline function is similar to a normal function. The only difference is that we place a keyword inline before the function name.

What is reified type Kotlin?

AndroidMobile DevelopmentApps/ApplicationsKotlin. "reified" is a special type of keyword that helps Kotlin developers to access the information related to a class at runtime. "reified" can only be used with inline functions.

What is inline function in Java?

If a function is inline, the compiler places a copy of the code of that function at each point where the function is called at compile time.

What is inline Val in Kotlin?

In order to reduce the memory overhead of such higher-order functions or lambda expressions, we can use the inline keyword which ultimately requests the compiler to not allocate memory and simply copy the inlined code of that function at the calling place. Example: Kotlin.


1 Answers

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.

like image 101
Rafal G. Avatar answered Dec 22 '22 04:12

Rafal G.