Does anybody know a solution for this problem? <ht...
# multiplatform
a
g
You cannot. This is jvm only feature
But you can use expect/actual declaration and extract this code to jvm and implement in some different way in other platforms
a
do you know about a library which does this?
Seems like that there is a proxy object in javascript as well
e
@gildor do you know if kapt based approaches are even possible? Generating instead of reflecting code?
🕵️‍♂️ 1
d
You can generate code with kotlin dynamically on the jvm, so yes. It's a very powerful feature.
e
how about, generate code on KN?
g
do you know about a library which does this?
Does what? proxy? It’s platform specific API so should be done on platfrom specific code.
@Ema Kapt based on Java APT, so it’s JVM only API But you can use it to generate some Kotlin code that can be used on any platform. It will be additional build step, where you generate some common code, than build it using MPP
👍 1
a
I think I'll try to reconcile javascript's proxy with java's proxy instead
and provide a common api for it
i don't really want to generate code
or have my users bother with it
thx for the ideas 👍
d
@addamsson I’m in the same limbo here 😄 Actually I’m using
Proxy
on Jvm and
TODO()
on KN & JS, since they aren’t my priority actually and hoping in a better solution than code-gen, please keep in touch here on StackOF, I’ve starred your post, just in case
😂 1
a
Copy code
TODO()
this literally made me laugh out loud 😄
👍
d
TODO()
is the developers’s 42 😄
✔️ 1
g
just curious what is your use case for Proxy
d
That's mine https://github.com/4face-studi0/Ermes Tbh I'm also curious about Adam
g
So Retrofit like use case. Yeah, I see
I don’t think that it will be possible to implement something like this for MPP before Compiler Plugins API will be available
or some another approach, like function delegation, but it also requires language support
For now I just use ktor-http-client for this (but also use interface to abstract it)
d
For now I'm just exploring kotlin multiplatform and I'm very happy to see at least the jvm part is working. Then, with time, I'll see if "something new" will come to kotlin-mp to help me on that, or maybe choose a complete different approach.
a
@Davide Giuseppe Farella I did some research
I tried using javascript's
Proxy
as an
external
class
but it quickly turned out that javascript's proxy is not a real proxy
when you careate a proxy for a
Foo
interface you get back a
Proxy
and not an object which implements
Foo
so I'm kinda stuck with this idea
while Java's proxy works as it is supposed to work javascript's proxy does not adhere to the proxy pattern
d
So basically
Copy code
interface Foo {
    fun bar(): Int
}
become
Copy code
class Proxy {
    fun bar() = 4 // for instance
}
?
a
no, the whole point would have been to supply an interface
and get a proxy instance back like
Copy code
val foo: Foo = createProxyFrom(Foo::class)
this is the proxy pattern
but javascript doesn't support it
d
Yes, I just didn’t understand what that Js lib does instead of that
I mean, at runtime, my
Foo
interface implementation become ( basically )
Copy code
class FooImpl: Foo {
    override fun bar() = 4
}
What about that Proxy lib?
a
this is not a lib but a built-in class in javascript
what it does is that you give it an object
it wraps the object
and you use the proxy from that point like it was that object
given javascript's dynamic nature it is not a problem that you get back a
Proxy
instead of a
Foo
but this is a problem in Kotlin since you can't cast a
Proxy
to a
Foo
I pasted a link to the docs above ☝️
d
Ok, so I get it right, basically I’ll have class FooImpl : Foo
I’m taking a quick look at that
Anyway maybe that could fit my usecase, I’ll need more valutations. Thanks for now
a
👍