What are the options for using Kotlin's built-in properties?

As a getter or setter property usually does not have a function as an argument, but is reified , what are the advantages / benefits of using inline properties?

If the benefits would be to reduce the cost of calling a method, why not make all getter / setter inline properties the default?

Kotlin intrinsic properties

Eg.

 val foo: Foo inline get() = Foo() var bar: Bar get() = ... inline set(v) { ... } 
+7
kotlin
source share
1 answer

Here are the built-in discussion properties:

An example of a parameter of type reified:

 inline val <reified T : PsiElement> T.nextSiblingOfSameType: T? get() = PsiTreeUtil.getNextSiblingOfType(this, T::class.java) 

Another use case is to hide some properties from the binary interface of the library. In the Kotlin standard library, along with the @InlineOnly annotation @InlineOnly this may allow in the future to exclude declarations of such properties from class files, reducing the number of methods, this will mainly benefit Android with a 64 percent method limit.

+7
source share

All Articles