Purpose of final and sealed

前端 未结 3 994
挽巷
挽巷 2020-12-19 03:18

Why would anyone want to mark a class as final or sealed?

3条回答
  •  执念已碎
    2020-12-19 04:07

    Because creating a type for inheritance is much harder work than most folks think. It is best to mark all types this way by default as this will prevent others from inheriting from a type that was never intended to be extended.

    Whether or not a type should be extended is a decision of the developer who created it, not the developer who comes along later and wants to extend it.

提交回复
热议问题