patternjavaModerate
Looping over a list, checking a boolean and return value
Viewed 0 times
loopingbooleanreturncheckingvalueandlistover
Problem
There are a number of different ways to do this. What do people prefer and why?
public boolean checkNameStartsWith(List foos) {
for (Foo foo : foos) {
if (!(foo.getName().startsWith("bar"))) {
return Boolean.FALSE;
}
}
return Boolean.TRUE;
}Solution
I'd change
Boolean.FALSE to false and Boolean.TRUE to true. Using the constants objects from Boolean is rather unnecessary since the method returns with primitive boolean.Context
StackExchange Code Review Q#18302, answer score: 14
Revisions (0)
No revisions yet.