Search code examples
javabytecode

Purpose of iconst_x


Why do we have the iconst_* instructions?

Why would I ever want to use these instead of bipush?

I found this StackOverflow question when searching but it does not properly answer my question.


Solution

  • Because a bipush instruction takes two bytes in the bytecode, and an iconst_* instruction takes one byte.