Frage

For example:

i) using a value

Util.arrayCopyNonAtomic(buffer,(short)(offset+20), keyTrack, PARAMETER_OFFSET, **(short) 6**);

ii) using a final variable

final static short length=6;
Util.arrayCopyNonAtomic(buffer,(short)(offset+20), keyTrack, PARAMETER_OFFSET, **length**);

so which one is better for javacard development? (let's just say I'm gonna use a lot of "6" later on)

War es hilfreich?

Lösung

Using final static is better if related to constants. The size of the generated binary for both cases are the same. However, ii) has advantage in code readability and also easier to maintain (if you need to change the value, you only need to change in one place).

NOTE: to avoid confusion, a variable is written as camelCase while a constant (final static) is written using UPPER_CASE. Example:

Util.arrayCopyNonAtomic(buffer, (short) (offset + 20), 
                        keyTrack, PARAMETER_OFFSET, LEN_OF_KEY);

Andere Tipps

Fields that are final and static and of a primitive type are inlined by the Java compiler as discussed in the Java Language Specification, section 13.4.9. This is independent of JavaCard because it happens even before the conversion to JavaCard binary format (CAP file) takes place.

So, the final binary code will be strictly identical.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top