문제

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)

도움이 되었습니까?

해결책

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);

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top