Assert a good practice or not?

前端 未结 7 1407
礼貌的吻别
礼貌的吻别 2021-01-30 05:02

Is it a good practice to use Assert for function parameters to enforce their validity. I was going through the source code of Spring Framework and I noticed that they use

7条回答
  •  星月不相逢
    2021-01-30 05:39

    Based on Sun's guide on assertions, you should not use assertions for argument checking in public methods.

    Argument checking is typically part of the published specifications (or contract) of a method, and these specifications must be obeyed whether assertions are enabled or disabled.

提交回复
热议问题