Java 8: Merging strings [] and int [] in Object [] when checking bytecode

I am reading section 4.10.2.2 of the specification for JVM version 8 ( https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html ) how to check the bytecode. In this case, what happens in the control flow when the stack now contains a slot with int [] when exiting from one source and String [] when switching from another source.

I read the following, which was not in versions 7 of the JVM versions:

If the corresponding values ​​are types of reference array types, then their sizes are checked. If the array types are the same size, then the combined value is a reference to an instance of the array type, which is the first common supertype of both types of arrays. (If one or both array types are of a primitive element type, then an object is used instead.)

...

Even int [] and String [] can be combined; the result is Object [], because Object is used instead of int when calculating the first common supertype.

This makes no sense to me, because it would mean that int [] could be passed to object []. But in Java arrays, primitive types cannot be ported to Object [].

Can anyone explain the rationale for this?

+4
1

, , , JVM ( , , , - ).

in , 2013 .

, int [] String [], . , ( Java 1.8.0_111).

+3

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


All Articles