Have you ever skipped a section of code you wanted to dig into when you Debug your program because you clicked “Next” too fast? Do you want to go back to the previous step?

IDEA provides an opportunity to help you roll back code, but it’s not a panacea. Ok, the use of this function will be discussed in detail below!

Use the Reset Frame rollback operation

I wonder if you have paid attention to the button “Reset Frame” marked in the picture below when debugging. This is the protagonist to be introduced today.

What can not be rolled back

For example: the following order structure, will not be able to return:

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

When can I roll back

Consider the following situation:

void test2(a) {
    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;
}
Copy the code

There are two functions here, test2 calling add. When we go to int c = add(a, b), we’re going to go to add. At this point, the contents of the add function can be Reset Frame back and forth to the statement entered by the previous function.

If you look at the text understanding difficulties, here DD recorded a video, you can see the specific operation to help understand, of course, their own practical operation will feel more oh!

Can’t find the Reset Frame? Look for the Drop Frame

By the way, I can’t find the Reset Frame during Debug.

Reset Frame is not available until IDEA 2022.1. But don’t worry, this version also had this feature before, but it wasn’t called that. Instead, it was called Drop Frame, which is the button shown below.

Well, that’s all for today’s sharing, and if you think this is useful, be sure to practice! Finally, remember to help support three companies, follow me, continue to share more development tips for everyone!

Welcome to pay attention to my public number: program ape DD. Learn cutting-edge industry news, share in-depth technical know-how, and obtain high-quality learning resources at the first time