gpt4 book ai didi

java - 所有 Android 类的实际基类是什么?

转载 作者:行者123 更新时间:2023-12-01 20:02:43 25 4
gpt4 key购买 nike

之前,我读过一些文章和教程,说所有 Android 组件的基类是 Application。但是当我更深入地研究继承时,我发现 Application 类继承自 ContextWrapper ,而后者也同样继承了 Context 类。

有趣的是Activity类也继承自ContetxtWrapper

为什么 Context 类不被称为所有 Android 组件的基类?

最佳答案

The Application class in Android is the base class within an Android app that contains all other components such as activities and services. The Application class, or any subclass of the Application class, is instantiated before any other class when the process for your application/package is created.

This class is primarily used for initialization of global state before the first Activity is displayed. Note that custom Application objects should be used carefully and are often not needed at all

Reference

 Why isn't the Context class referred to as the base class of all
android components?

The Application class in Android is the base class within an Android app that contains all other components such as activities and services.

我认为上面的行会消除您的困惑,因为基类不仅意味着它实现/扩展的内容,而且更多地意味着它包含的内容。

按照你的逻辑,如果你深入层次结构,最后所有类(如 Application/Activity/ContextWrapper)都将扩展[Object Class][2]

所以对象类应该是Android中的基类。

但是,

正如文档所说的

Class Object is the root of the class hierarchy. Every class has Object as a superclass. All objects, including arrays, implement the methods of this class.

关于java - 所有 Android 类的实际基类是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59004221/

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