I'm seeing override by an inline function is only ...
# compiler
l
I'm seeing override by an inline function is only a warning that can be suppressed. What happens under the hood when I do it? Tries to resolve to inline when the type is the impl of the interface?
i
inline function bodies are not deleted after inlining. Thus, calling method from interface will result in calling inline function.
l
It's only using the inline function for private usage, or it can go beyond? If it can go beyond, that's something I'd try for inline classes so I still benefit from using interfaces and keeping my code flexible to implementation changes without the overhead of autoboxing.
k
If the function is resolved statically it's inlined, if you call it trough the interface it's not.
Copy code
interface Foo {
    fun foo()
}

class Bar: Foo {
    override inline fun foo() = print("test")
}

fun main() {
    val x: Bar = Bar()
    val y: Foo = Bar()
    
    x.foo()
    y.foo()
}
x.foo()
is inlined,
y.foo()
is not.
i
It's only using the inline function for private usage, or it can go beyond?
Depends on what you mean by "beyond". It is just like normal function in bytecode and you can call it from Java.
l
@karelpeeters foo bar examples are so hard to read IMO.
InterfaceA
,
ClassB
,
someProperty
, etc are more readable, don't you think?
@Ilmir Usmanov [JB] I meant just like Karel's example, outside of the private scope of the class (public access). Now I got it, thanks for the info!
k
Yeah I guess, I still had some foo-bar code from another question open in InteliJ simple smile