Java中“包含类的子类”的含义?

时间:2012-12-20 18:05:43

标签: java class

当我阅读a paper时,我遇到了“包含类的子类”这个表达式。那个containing class在Java中意味着什么?这是本文的摘录。

Primarily, this entailed three things: (i) studying the implementation of the entity, as well as its usage, to reason about the intent behind the functionality; (ii) performing static dependency analysis on the entity, and any other types, methods, or fields referenced by it, including constants; and (iii) examining the inheritance hierarchy and subclasses of the containing class. This approach took considerable time and effort to apply.

2 个答案:

答案 0 :(得分:3)

此示例具有包含类的子类:

class Parent {
    class Child {
    }
}

class ParentSubclass extends Parent {
    void whatever() {
        new Child(); // Creates an instance of Parent.Child
    }
}

ParentSubclass包含Child子类。请注意Parent(或其子类) 之外的new Child()将不起作用,因为您需要来包含("外部")类来实例化非static"内部"类。

当您现在向[{1}}添加方法doSomething时,事情变得有点疯狂,在Parent中调用它,但在Child中覆盖它。

ParentSubclass

这样的情况使静态代码分析变得非常困难。

答案 1 :(得分:2)

由于我无法访问该论文,这是我最好的猜测:在Java中,类可以以多种方式相互关联:除了彼此继承之外,类还可以嵌套在彼此里面。

这是一个继承自嵌套类的类的类的示例:

public class Outer {
    public void doSomething() {
        // ...does something
    }
    private static class Inner extends Outer {
        public void doSomething() {
            // ...does something else
        }
    }
}

在上面的示例中,Inner继承自Outer,其作为其包含的类。