gpt4 book ai didi

android - 如果我们对 Android Views 使用私有(private)访问修饰符有什么坏处吗?

转载 作者:行者123 更新时间:2023-11-29 15:03:54 27 4
gpt4 key购买 nike

例如,下面的代码对吗?

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.

来源:Butterknife View injection

关于android - 如果我们对 Android Views 使用私有(private)访问修饰符有什么坏处吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40586817/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com