isAbstract() Modifier returning Incorrect result - Why?

Joker :

To my understanding the following code should print False as output

However, when I ran this code it is printing True as output.

From Java docs:

Return true if the integer argument includes the abstract modifier, false otherwise.

public class Test{
    public static void main(String[] args) {
        System.out.println(Modifier.isAbstract(byte[].class.getModifiers())); 
    }
}

Can some one help me understand this behavior ?

Eran :

The Javadoc of int java.lang.Class.getModifiers() specifies what should be returned for some of the modifiers for array types (for example, the final modifier is required to be true and the interface modifier is required to be false). On the other hand, it doesn't specify what the abstract or static modifiers should be for array types, which means the decision to return true or false is not documented in the JDK. Therefore any implementation can choose to return either true or false.

int java.lang.Class.getModifiers()

Returns the Java language modifiers for this class or interface, encoded in an integer. The modifiers consist of the Java Virtual Machine's constants for public, protected, private, final, static, abstract and interface; they should be decoded using the methods of class Modifier.

If the underlying class is an array class, then its public, private and protected modifiers are the same as those of its component type. If this Class represents a primitive type or void, its public modifier is always true, and its protected and private modifiers are always false. If this object represents an array class, a primitive type or void, then its final modifier is always true and its interface modifier is always false. The values of its other modifiers are not determined by this specification.

The modifier encodings are defined in The Java Virtual Machine Specification, table 4.1.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=35056&siteId=1