I have two methods:
public void test() {
for (int i = 0; i <= 10; i++) {
a();
}
}
public void a() {
// ...
}
Suppose the test method is fixed, I can not modify it.
How can I break the for loop in the a method?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can throw an unchecked exception.
Another solution is to sub-class the class which has the first method and fix it so it can stop early e.g. if a() return true.