为什么"AlertDialog.Builder"的命名约定很奇怪?而不是"AlertDialogBuilder";在Android中 [英] Why strange naming convention of "AlertDialog.Builder" instead of "AlertDialogBuilder" in Android
本文介绍了为什么"AlertDialog.Builder"的命名约定很奇怪?而不是"AlertDialogBuilder";在Android中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么不
AlertDialogBuilder builder = new AlertDialogBuilder(this);
builder.setTitle("foo");
代替
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("foo");
更新:我想知道这种写作/组织背后的原因
推荐答案
Builder 是 AlertDialog 类中的静态内部类.因此,要创建 Builder 类对象,您需要调用 AlertDialog.Builder .
Builder is the static inner class inside the AlertDialog class. So to create a Builder class object, you need to call AlertDialog.Builder.
因为没有像 AlertDialogBuilder 这样的类,所以您不能这样做.
As there is no class like AlertDialogBuilder so you cannot do that.
如果您愿意,也可以像下面这样使用.
If you want you can also use as like bellow.
Builder builder = new Builder(this);
builder.setTitle("foo");
但是要像这样使用,您需要将 Builder 类导入到您的类中,例如
But to use like this you need to import the Builder class to your class like
import android.app.AlertDialog.Builder;
而不是仅仅
import android.app.AlertDialog;
一个简单的例子
class A{
static class B{}
}
您不能使用
AB obj = new AB();
您必须使用
A.B obj = new A.B();
希望您现在清楚了.
这篇关于为什么"AlertDialog.Builder"的命名约定很奇怪?而不是"AlertDialogBuilder";在Android中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文