[英]How do classes instantiate in Java?
I came accross the following rule in JLS8/15.9.1 : 我在JLS8 / 15.9.1中遵循以下规则:
The Identifier after the new token must unambiguously denote an inner class that is accessible, non-abstract, not an enum type, and a member of the compile-time type of the Primary expression or the ExpressionName .
新标记之后的标识符必须明确表示可访问的内部类,非抽象的,不是枚举类型,以及主表达式或 ExpressionName 的编译时类型的 成员 。
I can't imagine what it the last restriction means. 我无法想象最后一次限制意味着什么。 Maybe you can give an example of such a member of the compile-time type of the Primary expression of the ExpressionName ?
也许您可以举例说明ExpressionName的Primary表达式的编译时类型的成员?
It says "If the class instance creation expression is qualified" .. then .. (your quotation) 它说“如果类实例创建表达式是合格的”..那么..(你的报价)
So, I guess it's this case: 所以,我猜是这种情况:
package test;
public class Test1 {
public class Test3{
}
}
And you instantiate it in another class like this: 并在另一个类中实例化它,如下所示:
package test;
import test.Test1.Test3;
public class Maker {
public static void main(String[] args) {
Test1 test1 = new Test1();
Test3 test3 = test1.new Test3();
}
}
Then, 然后,
test1.new Test3()
(test1.new, - a qualified new and not an unqualified new) test1.new Test3()
(test1.new, - 一个合格的new而不是一个不合格的new) Enjoy :) 请享用 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.