java中的复合类型

时间:2013-11-06 00:21:58

标签: java openjdk compound-type

在班级7-b147的open-jdk com.sun.tools.javac.code.Type中,我们有以下方法

public boolean isCompound(){
    return tsym.completer==null
    // Compound types can't have a completer.  Calling
    // flags() will complete the symbol causing the
    // compiler to load classes unnecessarily.  This led
    // to regression 6180021.
    && (tsym.flags() & COMPOUND)!=0;

}

Java中的复合类型是什么意思?

2 个答案:

答案 0 :(得分:2)

在Google上进行研究,它们似乎是学术上提出的Java扩展“。

“复合类型”被描述为必须实现多个类或接口的引用类型的说明符。这是为了帮助静态验证&必须全部实现多个API(接口)时的编译时正确性。

发明的例子:

[CustomerService,IRpcGateway,IOSGiComponent] custSvc = new CustomerService();

我找到了以下链接:

答案 1 :(得分:1)

Type.java中的TypeVar类具有以下注释,我认为很好地解释了COMPOUND类型的作用:

    /** The bound of this type variable; set from outside.
     *  Must be nonempty once it is set.
     *  For a bound, `bound' is the bound type itself.
     *  Multiple bounds are expressed as a single class type which has the
     *  individual bounds as superclass, respectively interfaces.
     *  The class type then has as `tsym' a compiler generated class `c',
     *  which has a flag COMPOUND and whose owner is the type variable
     *  itself. Furthermore, the erasure_field of the class
     *  points to the first class or interface bound.
     */

正如上面已经提到的,COMPOUND类型似乎模拟了由多个接口组成的类型变量的绑定类型,如:

class Example<T extends List<T> & Serializable>