Is it considered to be good practice or even safe to check if a condition can be evaluated and then evaluating the expression in the same if statement?
For example:
int[] values = new int[] { 1, 2, 3, 4 }
int index = 4;
if (index < values.length && values[index] == 4) {
System.out.println("value is 4")
}
In this example the condition is values[index] == 4
and I am using index < values.length
to check if it is safe to call it. However, I am doing this in the same if statement. Is it ok to do this?