Why are protected variables not allowed by default in Checkstyle?

前端 未结 3 1318
旧时难觅i
旧时难觅i 2021-01-03 18:07

I get a lot of warnings in eclipse like these:

Variable \'myVariable\' must be private and have accessor methods.

I think I get

3条回答
  •  半阙折子戏
    2021-01-03 18:41

    Allowing package access simplifies programming within a package, and reduces boilerplate code. Often times, access is only needed from within the package. Private access forces you to create a lot of nearly useless accessor methods. This actually has the effect of reducing encapsulation and information hiding because a class has to expose internal data/structure application wide instead of just package wide through public accessor methods. The default package visibility also makes testing easier because test classes live in the same package as well (in test dir/tree).

提交回复
热议问题