Is there asm nop equivalent in java?

前端 未结 5 1846
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-18 17:48

When I program C/C++ with Visual Studio I often use __asm nop; command to insert a noop code in order to have something to break on. For instance:

5条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-18 18:19

    In bytecode you have a nop instruction, but there's no nop statement in the Java language.

    You can add an extra ; on a line by itself and the code will still compile, but that's not much more meaningful than adding an empty line.

    Another "does nothing" statement could be:

    assert true;
    

    which has no side-effects what so ever, and can be turned off when executing the program.

    As it turns out, assert true does not seem to generate any bytecode instructions, which causes break-points on assert true to be skipped all together. Eclipse is however able to break on a statement such as

    assert Boolean.TRUE;
    

    which is quite similar.

提交回复
热议问题