1

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.

Community
  • 1
  • 1
  • 2
    Bytecode is strongly typed. `bipush` pushes a byte, `iconst` pushes an int. – aioobe Aug 05 '15 at 13:26
  • 2
    @aioobe Both the result of `bipush` and of `iconst` can be popped into an `int` variable, as demonstrated by the linked question. – Marko Topolnik Aug 05 '15 at 13:29
  • `Why would I ever want to use these instead of bipush?`---because it's a single-byte instruction, just like the other answer says. What more justification do you need? It's a simple space optimization. – Marko Topolnik Aug 05 '15 at 13:31

1 Answers1

0

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

yole
  • 92,896
  • 20
  • 260
  • 197