How to modify Java code while running in debug mode?

后端 未结 4 1936
难免孤独
难免孤独 2020-12-28 17:00

How can I enable this \"Debugging in Runtime\" Notch is talking about in this video in Eclipse?

As a test, I\'d like to be able to edit the output of the following c

相关标签:
4条回答
  • 2020-12-28 17:38

    You need to make sure that Project > Build Automatically is checked. Otherwise it might not work.

    0 讨论(0)
  • 2020-12-28 17:45

    After enable Project-> Build Automatically, hot swapping code in debug mode is ok to me

    0 讨论(0)
  • 2020-12-28 17:55

    Eclipse supports hot swapping code during debugging , out of the box.

    While debugging, just change any code and save it, Eclipse will automatically transfer the modified code to the target VM.

    Note that you can't make structural changes to the code, like adding new methods, changing method signature or adding new fields. But you can change the code within a method.

    EDIT: Note that changing the code during deubgging will make that method re-execute form the beginning, resetting the local variables in that method.

    0 讨论(0)
  • I may misunderstand the question, but if you run a program in Eclipse in debug mode (Run/Debug), you can edit the content of methods during the program runs (if JVM supports it). Regularly you can not change the imports, method signatures, class definitons, etc, just the content of the methods.

    0 讨论(0)
提交回复
热议问题