public static @interface Java4C.InstanceType
A reference in C refers always this instance type though the reference has a lesser type.
In Java the methods are override-able normally, because a final
designation
to prevent overriding is written only if the ability to override should prevent in inheriting classes.
Therefore the most of methods should be called in a override-able mode, using the method table-call.
But that is not economically in calculation time, and in some cases it is unnecessary.
It is against the C-style of programming and testing.
The difference provocation is: In a object oriented architecture interfaces should be used
to divide software in independent parts. Interfaces are the main choice to do so, base classes
are the other choice. So specific implementations can be implemented without cross effects.
But therefore the overridden methods appear as the only one solution.
In opposite to Java the independence of modules are realizes in C using forward declarations of methods
in header files and their implementation in separated C-files (compiling units). The linker
have to link only with knowledge of the labels (method names) without knowledge of any implementation details.
This form of independence can't realize the polymorphism in opposite to interfaces and super classes,
only the aspect of independence is regarded. But this aspect is the prior aspect mostly.
The solution of this provocation is found in the following way: If it is known, that a reference
references a determined instance in the C-implementation, it can be designated with a
@ java2c=instanceType:"Type".
-annotation in its comment block. Another way is
using a final assignment final IfcType ref = new Type();
, what generates
an embedded instance. Than the Java2C-translator
generates a non-overridden calling of the method of the designated instance type
for using that reference. The annotation is the decision written in the source
in knowledge of the implementation goals. In Java it isn't active. So in Java several implementations
can be implemented, at example for testing.
If the user is deceived in the usage of the reference, it is not detected in Java
neither by compiling nor by testing, because it isn't active there.
But it should be attracted attention in testing at C-(implementation)-level.
The Java2C-compiler may test the correctness of the designation @ java2c="instancetype".
,
because it translates the assignments too. But than all temporary used references should be designated
too. That don't may be helpfully.
But the designated reference can be tested in Java in Runtime, whether at least the designated type
is referenced, using a reference instanceof Type
-Java-sourcecode.
Than fatal errors are excluded, only if the instance is from a derived type, it isn't detected.
The instanceof
-check needs a small part of calculation time,
if the instance is from the expected type. Such tests are slowly only if the instance is from a far derived type,
than the implementation type should be searched in reflections. In the current case
only 2 indirect accesses and a compare operation is necessary in the implementation of
instanceof_ObjectJc(ref, reflection_Type).
A reference, which has a dedicated instance type, is determined in its FieldData#instanceClazz
- element.
This element is able to seen in the stc-File of the translated class with notation instance:
as part of the fieldIdents {...}
.
The method-call is translated to C using the Method#sImplementationName
.