|
From: Martin K. <Mar...@St...> - 2005-02-25 22:00:45
|
Hi folks,
while reviewing the code I found a construct that distracted me.
It is the BeanUtils.isAssignable method:
/* Determine if the given type is assignable from the given value,
* assuming setting by reflection. Considers primitive wrapper classes
* as assignable to the corresponding primitive types.
* [..] */
public static boolean isAssignable(Class type, Object value) {
return (value != null && isAssignable(type, value.getClass()) ||
(value == null) && !type.isPrimitive());
}
It seams odd to have something like: a && b || c && d. That is
not clearly clear which binds first and I guess this is not
which was intended.
By reducing the semantic we have:
A => value!=null
B => isAssignable...
C => value==null
D => !type.isPremitive()
So it reads:
return A && B || C && D; //What is this meaning?
I would say that this always true.
If it is not a premitve it is true, if it is null and not a premitve
it is the only thing where it might be returning null.
From the reading I guess it is ment to be:
return (A && B) || (C && D);
Cheers,
Martin (Kersten)
|