문제

I am overriding a method from superclass, however I want this method to be synchronized. Is it allowed? What could be the alternative?

도움이 되었습니까?

해결책

Yes, it's allowed as it doesn't change the contract but the implementation.

Think that you could always simply add a synchronized block :

synchronized(this) { 

just at the start of the method, which would achieve about the same result. There could also be other (possibly hidden) locks deeper in the method, which makes this really part of the implementation rather than the API.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top