Can anybody explain why we cannot declare a synchronized method in an interface, by giving a real world example.
Why we cannot use synchronized keyword in an interface method declaration
957 views Asked by Aqeel Ashiq At
1
Can anybody explain why we cannot declare a synchronized method in an interface, by giving a real world example.
The answer is simple, a synchronized is an implementation detail and it does not belong to an interface. In an interface all the methods do not have the implementation detail.
The docs says:
You may also refer: What is the reason why “synchronized” is not allowed in Java 8 interface methods?