6 ms·
At that point, why not just make types you want lock functionality for be declared as 'synchronized' in their class definition: synchronized class Foo {
by ShroudedNight 3y ago
At that point, why not just make types you want lock functionality for be declared as 'synchronized' in their class definition:
synchronized class Foo {
//...
}
- derefr 3y agoBecause, for the things that do care about synchronization, they might want multiple explicit MonitorSlot members. It makes more sense to just be able to synchronize on MonitorSlots directly, and then decide where they go. The only reason I added the `synchronized (this)` allowance was because the parent said that they think that that's "good ergonomics" — and presumably, the Java1.0 authors also thought that — and I was trying to suggest an alternative that would preserve what they consider "good ergonomics." But personally, if I was the sole dictator of Java1.0 language design with nobody else to please, I would just have `synchronize(MonitorSlot)` + explicitly-defined MonitorSlot members (that, if you declare one, must always be declared final, and cannot be assigned to in the constructor), and that's it. Just refer to them by name when you need one.