简体   繁体   English

为什么我无法访问android.widget包中的package-private字段?

[英]Why can't I access package-private fields in the android.widget package?

I'm attempting to override an Android View class to tweak the functionality just slightly. 我正在尝试覆盖Android View类以稍微调整功能。 But I need to modify a field that does not have a setter method. 但是我需要修改没有设置方法的字段。 I've placed the subclass in a package called android.widget . 我将子类放置在名为android.widget的包中。 Why can't I access any of the package-private member fields? 为什么我不能访问任何package-private成员字段? I notice that the compiler says they "cannot be resolved," rather than not being accessible. 我注意到编译器说它们“无法解决”,而不是无法访问。 Does this have something to do with how Android.jar is built? 这与Android.jar的构建方式有关吗?

Those methods are not part of the Android SDK and so therefore are unavailable to you directly from an SDK application. 这些方法不是Android SDK的一部分,因此无法直接从SDK应用程序使用。 If you are building firmware, you can access them directly. 如果要构建固件,则可以直接访问它们。 Presumably, your subclass could get at them via reflection, though bear in mind that such fields (or any other non-SDK stuff) is subject to change in any given Android release. 大概,您的子类可以通过反射来了解它们,但请记住,此类字段(或任何其他非SDK的东西)在任何给定的Android版本中都会发生变化。

It's also a side effect of class loaders. 这也是类加载器的副作用。 Your android.widget package is not the same android.widget package used by the system. 您的android.widget软件包与系统使用的android.widget软件包不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么不能在同一个包中调用另一个类的包私有方法呢? - Why can't I call a package-private method of another class that's a subclass of a class in the same package? Spring @Autowired 字段 - 哪个访问修饰符是私有的还是包私有的? - Spring @Autowired fields - which access modifier, private or package-private? 为什么Android类加载器允许从另一个包反射访问包私有类的公共字段? - Why does Android classloader allow reflective access to the public field of a package-private class from another package? 为什么私有访问方法比package-private更可取? - Why private access for methods is more preferable than package-private? 为什么Java Reflection无法在另一个包中找到类的包私有构造函数? - Why can't Java Reflection find the package-private constructor of a class in another package? 为什么JUnit 5默认访问修饰符更改为package-private - Why JUnit 5 default access modifier changed to package-private 如何在 IntelliJ 中禁用“访问可以是包私有的”消息? - How to disable "Access can be package-private" message in IntelliJ? 对于@Transactional方法,禁用警告“Access可以是包私有” - Disable warning “Access can be package-private” for @Transactional methods ProGuard可以将访问修饰符更改为程序包专用吗? - Can ProGuard change access modifers to package-private? 为什么枚举有一个包私有构造函数? - Why can a enum have a package-private constructor?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM