java - Why we cannot use synchronized keyword in an interface method declaration -
this question has answer here:
can explain why cannot declare synchronized method in interface, giving real world example.
the answer simple, synchronized implementation detail , not belong interface. in interface methods not have implementation detail.
the docs says:
note method declared in interface must not declared strictfp or native or synchronized, or compile-time error occurs, because keywords describe implementation properties rather interface properties. however, method declared in interface may implemented method declared strictfp or native or synchronized in class implements interface.
you may refer: what reason why “synchronized” not allowed in java 8 interface methods?
Comments
Post a Comment