Java – why can’t static and default interface methods be synchronized but can be strictfp?

See English answers > what is the reason why "synchronized" is not allowed in Java 8 interface methods? 1

People say synchronized is an implementation detail Then, strictfp is also an implementation detail, but this does not prevent strictfp from being allowed on static and default interface methods

If the class implementing the interface does not override the default method, it may be convenient to inherit the default method and synchronize it

I guess synchronized (and strictfp) is not inherited (am I here?), But this does not explain why strictfp also allows static and default interface methods

Solution

Strictfp keywordensure that your floating-point operations are consistent across all platforms Stricftp is the guarantee of the JVM. Your floating-point operations will be the same on all platforms, and you can expect floating-point operations to be portable and consistent

A method marked synchronized is actually an implementation detail and cannot be specified or controlled by any interface for any of its implementations As Brian Goetz explained, it is deliberately excluded from the default methods because they are inherently dangerous (emphasize my):

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>