Why does Java convert byte and short operands to ints during numeric promotion

StackOverflow https://stackoverflow.com/questions/4575637

  •  14-10-2019
  •  | 
  •  

سؤال

What are the reasons behind the extension of small datatypes (e.g. byte) to int during the Numeric Promotion process? Wouldn't it be possible to perform most of the operations directly on these smaller datatypes?

هل كانت مفيدة؟

المحلول

The VM is a virtual machine, the JIT translates this to native code and optimises it then. All registers are either 32-bit or 64-bit and "shorter" operations are not necessarily and faster.

نصائح أخرى

The VM does not support integers smaller than 4 octets, so when running in the VM you are operating on 4 octet ints or 8 octet longs. (Well it does for arrays, barray sarray, etc, just not for single values).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top