Question

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?

Was it helpful?

Solution

Researching on Google, they appear to be an academically proposed "extension" to Java.

"Compound types" are described as a specifier for reference-types which must implement multiple classes or interfaces. This is intended to help static verifiability & compile-time correctness when multiple APIs (interfaces) must all be implemented.

Invented example:

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

I found the following links:

OTHER TIPS

The TypeVar class in Type.java has the following comment that I think explains the role of COMPOUND type quite well:

    /** 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.
     */

So as was already mentioned above, a COMPOUND type seems to model the type of a bound of a type variable that is composed of multiple interfaces like:

class Example<T extends List<T> & Serializable>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top