Should i validate parameters in constructor?

前端 未结 4 1723
谎友^
谎友^ 2021-02-07 08:09

I am creating a web application following the MVC pattern.

In effective Java the author mentions to validate the parameters in the constructor of the class when creatin

4条回答
  •  失恋的感觉
    2021-02-07 08:37

    At the first sight it is not necessary to validate the parameters since the validation was done before. But you should take into consideration that your class will be used in other circumstances, you cannot be sure that every time the input of your constructor is valid.

提交回复
热议问题