gpt4 book ai didi

java - 有人怎么会意外地在 Java 中启动一个类呢?

转载 作者:行者123 更新时间:2023-12-01 09:55:06 28 4
gpt4 key购买 nike

我正在阅读 android 教程,并且遇到了以下代码:

public final class FeedReaderContract {
// To prevent someone from accidentally instantiating the contract class,
// give it an empty constructor.
public FeedReaderContract() {}

/* Inner class that defines the table contents */
public static abstract class FeedEntry implements BaseColumns {
public static final String TABLE_NAME = "entry";
public static final String COLUMN_NAME_ENTRY_ID = "entryid";
public static final String COLUMN_NAME_TITLE = "title";
public static final String COLUMN_NAME_SUBTITLE = "subtitle";
...
}
}

这是教程的链接: https://developer.android.com/training/basics/data-storage/databases.html#DbHelper

虽然我以前从事过 Java 工作,但我不明白为什么人们会意外地在 Java 中启动一个类。这怎么可能?

This不是我要找的。

最佳答案

我认为它应该是私有(private)的,例如:

private FeedReaderContract() {}

这将使开发人员无法实例化 FeedReaderContract 实例

关于java - 有人怎么会意外地在 Java 中启动一个类呢?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37298678/

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