Class C # getInterfaces () and Class C # getGenericInterfaces () return arrays of different lengths

If you take a class scala.runtime.AbstractPartialFunctionfrom Scala 2.10.2 (I did not check other versions) and compare the output AbstractPartialFunction.class.getInterfaces()and AbstractPartialFunction.class.getGenericInterfaces(), you may notice that the results do not match. Common interfaces: scala.Function1<T1, R>and scala.PartialFunction<T1, R>, and getInterfaces () returns only scala.PartialFunction. Create Scala documentation, I see that the general information is correct because PartialFunction is Function1.

The javadoc for getInterfaces says:

If this object represents a class, the return value is an array containing objects representing all the interfaces implemented by the class. The order of the interface objects in the array corresponds to the order of the interface names in the implements clause of the class declaration represented by this object.

and getGenericInterfaces has the same text.

From this (and from other texts, including information about the stack), I would conclude that the order and length of the arrays are equal. Only here it is not. What for?

I was able to reproduce this with several java7 and java8 so far, have not tried java6 or even java5.

EDIT:

Javap output for AbstractPartialFunction (header only, of course):

Compiled from "AbstractPartialFunction.scala"
public abstract class scala.runtime.AbstractPartialFunction<T1, R> implements scala.Function1<T1, R>, scala.PartialFunction<T1, R>`

Using asm lib and Textifier, I see this header information:

// class version 50.0 (50)
// access flags 0x421
// signature <T1:Ljava/lang/Object;R:Ljava/lang/Object;>Ljava/lang/Object;Lscala/Function1<TT1;TR;>;Lscala/PartialFunction<TT1;TR;>;
// declaration: scala/runtime/AbstractPartialFunction<T1, R> implements scala.Function1<T1, R>, scala.PartialFunction<T1, R>
public abstract class scala/runtime/AbstractPartialFunction implements scala/PartialFunction

plus ScalaSigAttribute. Of course, I did not show the methods in both cases.

+4
2
// Compiled from AbstractPartialFunction.scala (version 1.6 : 50.0, super bit)
// Signature: <T1:Ljava/lang/Object;R:Ljava/lang/Object;>Ljava/lang/Object;Lscala/Function1<TT1;TR;>;Lscala/PartialFunction<TT1;TR;>;
@scala.reflect.ScalaSignature(bytes="some bytes...")
public abstract class scala.runtime.AbstractPartialFunction implements scala.PartialFunction {

Java:

class AbstractPartialFunction implements PartialFunction, Function1 {}

PartialFunction Function1:

// Compiled from PartialFunction.scala (version 1.6 : 50.0, no super bit)
// Signature: <A:Ljava/lang/Object;B:Ljava/lang/Object;>Ljava/lang/Object;Lscala/Function1<TA;TB;>;
@scala.reflect.ScalaSignature(bytes="some bytes...")
public abstract interface scala.PartialFunction extends scala.Function1 {

Java:

ClassFile {
    u4             magic;
    u2             minor_version;
    u2             major_version;
    u2             constant_pool_count;
    cp_info        constant_pool[constant_pool_count-1];
    u2             access_flags;
    u2             this_class;
    u2             super_class;
    u2             interfaces_count;
    u2             interfaces[interfaces_count];
    u2             fields_count;
    field_info     fields[fields_count];
    u2             methods_count;
    method_info    methods[methods_count];
    u2             attributes_count;
    attribute_info attributes[attributes_count];
}

, , :

:

Signature , , , Java .

, , :

  • Class.getInterfaces()
  • Class.getGenericInterfaces()
  • Scala Function1 , PartialFunction Function1
  • Scala as-is

, Oracle JDK Java, , , , JVM .

+3

, ... , ...

, generics - . , , , , , . : generics, - javac .

, , , . Java, , , tools. Javadoc Android . , , - javac.

0

Source: https://habr.com/ru/post/1530600/


All Articles