java - Why we cannot use synchronized keyword in an interface method declaration -


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

Popular posts from this blog

symfony - TEST environment only: The database schema is not in sync with the current mapping file -

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -