I am creating a class for an application which has methods checking if the current time is within a specified range.
public boolean visitorEntry()
{
currentTime = LocalTime.now();
start = LocalTime.of(8, 30);
finish = LocalTime.of(22,0);
if (currentTime.isAfter(start) && currentTime.isBefore(finish))
return true;
else return false;
}
I am using NetBeans and am being told that the if statement is redundant. I assume my condition is logically incorrect and always evaluates to true but I don't understand why.
Thanks in advance.
What it means is you can write :
return currentTime.isAfter(start) && currentTime.isBefore(finish);
On NetBeans, if you hit Alt-Enter while the cursor is on if
and select "The if statement is redundant" it will do this simplification itself.
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