[英]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.