https://kotlinlang.org logo
Title
e

elect

10/12/2018, 9:41 AM
there isnt a way to have
inline
within
interface
methods?
only private or final methods can have it
k

karelpeeters

10/12/2018, 9:42 AM
How would that work? The compiler needs to know the actual implementation.
e

elect

10/12/2018, 9:42 AM
I'd be fine if I could declare it as final
e

Egor Trutenko

10/12/2018, 9:43 AM
You basically can't declare
interface
method as
final
e

elect

10/12/2018, 9:44 AM
exactly, so there is no way, isn't?
e

elizarov

10/12/2018, 9:44 AM
You can write an extension function on your interface.
👍 2
e

Egor Trutenko

10/12/2018, 9:45 AM
To clarify, why do you actually need to declare an interface method
inline
?
e

elect

10/12/2018, 9:49 AM
for performances and since I have a lambda in the arguments it makes sense
e

Egor Trutenko

10/12/2018, 9:53 AM
No it doesn't. Should your call with lambda be inlined or not depends on implementation of that method
e

elect

10/12/2018, 10:02 AM
that's the thing, I don't want implement that method
I'm perfectly fine with the common base method
e

Egor Trutenko

10/12/2018, 10:14 AM
I don't understand. So you have an interface with default implementation that you don't want to override and which operates on abstract properties of that interface, right?
e

elect

10/12/2018, 10:21 AM
abstract class GLCanvas {

    ...

    @Throws(AWTException::class)
    abstract fun lock()

    @Throws(AWTException::class)
    abstract fun unlock()

    @Throws(AWTException::class)
    inline fun <R> lock(block: () -> R): R =
            try {
                lock()
                block()
            } finally {
                unlock()
            }
}
k

karelpeeters

10/12/2018, 10:22 AM
You can just make that an extension function.
e

elect

10/12/2018, 10:22 AM
.. yes
yeah, I know, I tried and worked flawless. However I found that I also have a common property.. that's why I switched to
abstract class
k

karelpeeters

10/12/2018, 11:35 AM
...
e

elect

10/12/2018, 12:17 PM
eh sorry 😄