what to choose between require and assert in scala

前端 未结 5 1986
谎友^
谎友^ 2020-12-23 13:37

Both require and assert are used to perform certain checks during runtime to verify certain conditions.

So what is the basic difference bet

5条回答
  •  余生分开走
    2020-12-23 14:11

    In very simple language:

    Require is used to enforce a precondition on the caller of a function or the creator of an object of some class. Whereas, assert is used to check the code of the function itself. So, if a precondition fails, then you get an illegal argument exception. Whereas, if an assertion fails and it's not the caller's fault and consequently you get an assertion error.

提交回复
热议问题