Code in the constructor before or super in the generated class file when using the code coverage tool

I am using google code pro Analatics to measure code coverage.

Source

public class StackArray<T> implements Stack<T> { private int top; private T[] elements; public StackArray(Class<T> type, int size) { top = -1; elements = (T[]) Array.newInstance(type, size); } //Other stack related methods } 

Generated Class File

 import com.vladium.emma.rt.RT; import java.lang.reflect.Array; // Referenced classes of package ds.stack: // Stack public class StackArray implements Stack { private int top; private Object elements[]; private static final int $VRc[][]; /* synthetic field */ private static final long serialVersionUID = 0x927be770ed420794L; /* synthetic field */ public StackArray(Class type, int size) { int ai[] = ($VRc != null ? $VRc : $VRi())[0]; super(); top = -1; elements = (Object[])Array.newInstance(type, size); ai[0] = ai[0] + 1; } } 

My question is how is this line valid in the constructor before or super

 int ai[] = ($VRc != null ? $VRc : $VRi())[0]; 
+4
source share
1 answer

The restriction on super() or this() allowed only as the first instruction in the constructor - this is a restriction imposed by Java compilers, and not bytecode / object classes.

A "generated class file" is either a decompilation of the class of an object that will not compile under the normal Java compiler, or is compatible with modified Java that allows such constructs. In both cases, the code looks 99% Java source, but it is not.

+2
source

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


All Articles