为什么我们应该将 urimatcher 定义保留在内容提供程序的静态花括号中?

发布于 2024-11-05 17:53:03 字数 203 浏览 4 评论 0原文

我对内容提供商有疑问。
每次当我编写内容提供程序时,我都会将 URI MATCHER 定义放在静态括号中,但 URI MATCHER 被声明为该类的私有数据成员。只有定义(new UriMatcher) 被放置在静态括号中。

有人请告诉我原因吗。我尝试谷歌搜索但找不到答案。我也会尝试,如果有人知道请告诉我。

谢谢&问候,
S苏曼185

I got a doubt regarding the content provider.
Everytime when i am write the content provider, i am placing the URI MATCHER definition in the static brackets but the URI MATCHER is declared a private data member of the class. Only definition(new UriMatcher) is being placed in the static brackets.

Will anyone please let me know the reason. I tried googling but not able to find the answer. Me too will try please let me know if anyone knows already.

Thanks & Regards,
SSuman185

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蔚蓝源自深海 2024-11-12 17:53:03

它是一个静态初始化块
当您定义成员或类变量时,该值必须放在一行中(即使您将其间隔更多),并且它不能包含复杂的逻辑。

对于成员变量,您可以在构造函数中进行这种复杂的初始化。

本质上,静态初始化块是类变量的构造函数,允许您在初始化时使用更复杂的表达式。无论创建了多少个实例,它仅在类首次加载时执行一次。

私有成员仅意味着该变量不能被其他类访问,但该类本身仍然可以访问。因此,静态初始化块仅创建 URIMatcher 一次(在类加载时),无论有多少个实例。

It is a static initialization block.
When you define a member or class variable the value must fit on a single line (even if you space it over more), and it cannot include complicated logic.

For member variables you can do this complicated initialization in the Constructor.

Essentially a static initialization block is a constructor for your class variables, allowing you to use more complicated expressions when initializing. It is only executed once, when the class is first loaded, no matter how many instances are created.

A private member just means the variable is not accessible to other classes, it is still accessible to the class itself. So the static initialization block only creates the URIMatcher once (when the class is loaded), no matter how many instances there are.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文