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

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

  •  14-10-2019
  •  | 
  •  

Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top