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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -