1

When you are debugging the program, have you ever encountered that the code you want to analyze in depth is skipped because the "Next" button is pressed too fast? Do you really want to have an operation like "back to the previous step"?

IDEA provides an opportunity to help you roll back code, but this method is not a panacea. Well, let's talk about the use of this function in detail!

Use Reset Frame to roll back an operation

I don't know if you have noticed the button shown in the Reset Frame when you are debugging, this is the protagonist to be introduced today.

file

What can't go back

For example, the following sequence structure cannot be reversed:

 void test() {
    int a = 1;
    int b = 2;
    int c = a + b;
    System.out.println(c);
}

What can go back

Let's take a look at the following situation:

 void test2() {
    int a = 1;
    int b = 2;
    int c = add(a, b);
    System.out.println(c);
}

int add(int a, int b) {
    System.out.println("a = " + a);
    System.out.println("b = " + b);
    return a + b;
}

There are two functions here, test2 function will call add function. When the program executes to the sentence int c = add(a, b) , it will enter the add function. At this point, the content executed in the add function can go back and forth through Reset Frame to the statement entered by the previous function.

If you find it difficult to understand the text, DD has recorded a video here, you can see the specific operation to help you understand, of course, you will feel better if you practice it yourself!

Can't find Reset Frame? Find Drop Frame

By the way, some friends may ask: Why can't I find Reset Frame when I debug?

In fact, this is related to the version, Reset Frame is only available after the IDEA 2022.1 version. But don't worry, this version also had this function before, but the name is not called this, but called Drop Frame , which is the button shown in the figure below.

file

Well, today's sharing is here. If you think this sharing is useful to you, remember to practice it! Finally, remember to help three consecutive support, follow me, and continue to share more development knowledge with you!

Welcome to my public account: Programmer DD. Learn about cutting-edge industry news for the first time, share in-depth technical dry goods, and obtain high-quality learning resources

程序猿DD
2.2k 声望2.8k 粉丝

作品:《Spring Cloud微服务实战》、SpringForAll社区、OpenWrite、Youtube中文配音