例如,下面的代码对吗?
private LinearLayout layout1;
private LinearLayout layout2;
private LinearLayout layout3;
最佳答案
不,它没有害处。但是,如果您正在使用某种 View 注入(inject)库,例如 ButterKnife
,它不会让您将 View 定义为 private
。原因如下:
The reason that Butter Knife requires views not be private is that it actually generates code which sets the fields. The code that it generates lives in the same package as your class which is why the field must be package-private, protected, or public. If the field was private the generated code would fail to compile since it cannot access the private field.
关于android - 如果我们对 Android Views 使用私有(private)访问修饰符有什么坏处吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40586817/