推理方法的最终结果 [英] Reasoning for making a method final
问题描述
对不起,在这里快速提问,只是在我的笔记中找到了一些关于最终制作方法的内容。我的笔记声称你应该为这个方法做一个最后的方法:
Sorry, quick question here, just found something in my notes I don't understand in relation to making a method final. My notes claim you should make a method final for this reason :
使得无法强制执行不变量。
Makes it impossible to enforce invariants.
字符串应该表现为字符串。
A String should behave as a String.
我真的不明白这是什么意思。有人可以帮我分手吗?非常感谢。
I don't really understand what is meant by this. Can someone please break it down for me ? Thanks a lot.
推荐答案
我猜应该说可以强制执行不变量。基本上,如果有人可以覆盖一个方法,那么他们可以改变影响你的类不变量的行为。
I would guess that should have said "Make it possible to enforce invariants". Basically, if someone can override a method, then they can change behaviors affecting your class's invariants.
这篇关于推理方法的最终结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!