I asked the below question a couple of days ago bu...
# announcements
n
I asked the below question a couple of days ago but got no answer. I tried to convince my callers that adding
.INSTANCE
is really not a big deal but so far they are not buying it... Anyone has a better idea? I have a mixed Kotlin and Java codebase and a singleton in Kotlin with its methods called from Java. The singleton
Manager
delegates all calls to an implementation of an interface
Service
(there are multiple possible implementations of
Service
,
Manager
picks one at startup). Right now, the code does
Copy code
object Manager { val delegate = pickImpl(); @JvmStatic fun foo() = delegate.foo(); @JvmStatic fun bar(a: Int) = delegate.bar(a); ... }
and the Java code calls
Manager.foo()
. This could be simplified to
object Manager : Service by pickImpl()
but then the Java code has to be changed to call
Manager.INSTANCE.foo()
. Is there a way to use delegation but retain the
@JVMStatic
for the Java code?
m
I assume you've tried putting
@JvmStatic
on the
foo
function in the
Service
interface? And discovered it doesn't get 'inherited'? That's about the only thing I can think of to try.