https://kotlinlang.org logo
Title
h

hho

02/06/2018, 1:40 PM
I have Java code which uses
object.wait()
and
object.notify()
. What's the best way to convert this to Kotlin? The converter in IntelliJ replaces
Object
with
Any?
, but
wait()
and
notify()
are of course not defined on
Any
.
n

nfrankel

02/06/2018, 1:45 PM
thread blocking is the worst possible solution regarding thread-safety it was also the only one available in old JDK versions first, you might want to get a little information about
Future
,
CompletableFuture
, etc.
because i’m afraid it’s not worth to migrate your code directly without refactoring it
h

hho

02/06/2018, 1:47 PM
Thanks. I thought about passing around a
CountDownLatch
, but you're right; a bigger refactoring is probably necessary
👍 1
e

elizarov

02/06/2018, 6:28 PM
If you need to port your Java code wihtout much hassle you can use
(obj as Object).wait()
(same with
notify()
)