Would it have been bad if, instead of synchronized
keyword we had @Synchronized
annotation? Would an annotation be more natural in this case (because you can override a synchronized
method with a non-synchronized method - thus synchronized
says nothing about the method itself but rather specifies something in addition to the method (that the method is guarded in a certain way), so it's not really a keyword?)
synchronized is used on blocks of code and you can't add an annotation to a block of code.
You could have @synchronized
on methods or even classes but Java didn't support annotations when Java was first introduced.
I think its important enough to deserves its own keyword. ;)
Synchronized transforms practically directly into monitorenter/monitorexit on the byte code level. And you specify what to synchronized on, you can't do that with an annotation:
synchronized (myLock) {
}
So it makes perfect sense to me that it is a keyword.
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