Does scala support synchronized object (/static) methods? I am looking for:
synchronized def myObjectMethod(): <SomeReturnType> = {
..
}
If this were not supported, what is the equivalent in scala ?
synchronized
in scala is just a method1. So you can do
def myObjectMethod: SomeReturnType = synchronized {
// stuff
}
It's actually a special method injected by the compiler, more details here: How is the synchronized method on AnyRef implemented?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With