I was migrating a java project to groovy. Then I got an if condition is giving false
in Groovy which was giving true
in Java code.
int status_num = 301
if (status_num / 100 == 3) {
throw new GoogleServiceConditionException("Google Search System is under maintenance")
}
The if condition is giving false for groovy. For Java, it gives true.
How can I mitigate the issue?
I have searched over Groovy documentation. It say's like below:
For integer division like in Java, you should use the intdiv() method, as Groovy doesn’t provide a dedicated integer division operator symbol.
So, I have changed the code like below.
if (status_num.intdiv(100) == 3) {
throw new GoogleServiceConditionException("Google Search System is under maintenance")
}
Now, it works fine.
For more, you can go through the tutorial: The case of the division operator
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With