https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
z

zsqw123

09/23/2023, 5:42 PM
I want to do that allows partial implementations not actually written in class, eg:
Copy code
class Foo {
    api fun bar(): String
}

// write in another file
impl fun Foo.bar() = "bar"
The reason I want to implement this is that I want the actual implementation of the
bar
function to be implemented by KSP generated code, and I want it to be a member function that does not require import and does not need to wait for
KspDebug
to finish executing before calling to
h

hfhbd

09/23/2023, 5:47 PM
What about the existing inheritance options, interface or even an open/abstract class? Alternatively you could do it with an compiler plugin, so afaik there is no need to change the language.
z

zsqw123

09/23/2023, 6:07 PM
Maybe kotlin language advocate
final
rather than open/abstract.😂 and I don't really want it to have subclasses. Using KCP also requires synchronous development of IDE plugins to avoid IDE errors for not implemented, and many languages actually have similar api and implementations separate logic(like header) And, api separation is actually a way to explicitly declare api. it is also a easy way to optimizing compiler's tracking of abi changes for incremental compile. It also provide a simple way to compare the api changes between old and new versions. Also, if adding a new keyword doesn't good, can we consider existing
external
keyword? Not just for interacting with native, but also for this additional api/impl seperation?
e

ephemient

09/23/2023, 8:46 PM
Copy code
class Foo {
    fun bar(): String = barImpl()
}

internal fun Foo.barImpl() = "bar"
a

asdf asdf

09/24/2023, 12:07 AM
Seems a lot like
expect/actual
, although might be sort of weird to use it on just a single platform
z

zsqw123

09/24/2023, 2:14 AM
yeah!👍 it is
expect/actual
, but I want to use it in single sourceset(platform), and maybe when no
actual
impl, it will not show the ide error
d

Derek Peirce

09/28/2023, 7:56 PM
This has value over an interface because you can declare a constructor that your other classes can access directly, while still generating the implementation of some methods. You can't do the same for a purely generated implementation class.