Java – can final be removed from the class definition for backward compatibility?

I am currently reading effective java written by Joshua Bloch. Item 17 is "inherit the design and documentation, or prohibit it" The author suggests that inheritance is prohibited by default

Is it safe to declare the class final by default? If you need to extend the class, delete the final keyword in future releases? Does it break backward compatibility with code compiled in previous versions?

If so, let all classes eventually become a safer bet and remove it in future versions only if there is a need for good support

Solution

It does not destroy binary or source compatibility, which is one of the reasons why the course finally becomes a good idea; It's always possible to change your mind

The Java Language Specification,§13.4. 2. Binary compatibility is described as follows:

I think you can still constitute an explanatory example that can break the program; For example, bytecode - generates a class that inherits from the so-called final class, then loads the generated class and depends on getting verifyerror

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
分享
二维码
< <上一篇
下一篇>>