I have a mixed Kotlin and Java codebase and a sing...
# announcements
n
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?