Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the if statement is redundant java

Tags:

java

netbeans

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.

like image 261
Nick Avatar asked Nov 29 '22 06:11

Nick


1 Answers

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.

like image 51
Manos Nikolaidis Avatar answered Dec 09 '22 14:12

Manos Nikolaidis