5

In open-jdk 7-b147 in class com.sun.tools.javac.code.Type we have the following method

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;

}

What does mean compound type in Java?

4

2 回答 2

2

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

“复合类型”被描述为必须实现多个类或接口的引用类型的说明符。当必须实现多个 API(接口)时,这旨在帮助静态可验证性和编译时正确性。

发明的例子:

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

我找到了以下链接:

于 2013-11-06T00:30:40.630 回答
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>
于 2013-12-10T14:36:27.587 回答