|
From: Erwin B. <er...@kl...> - 2005-02-26 21:12:18
|
Hi,
I'm almost afraid to intrude, but the expression here, written as
(A && B) || (C && D)
isn't it actually like this?
(A && B) || (!A && D)
which could be written shorter as
A ? B : D
or in this case:
return (value != null ? isAssignable(type, value.getClass()) :
!type.isPrimitive());
Perhaps an if-statement would be clearer, but if you want to write it as
a single expression, isn't the ternary conditional operator a clearer
way of expressing this?
Regards,
Erwin Bolwidt
Juergen Hoeller wrote:
>Actually, there's nothing wrong with this (provided that I haven't
>misunderstood the issue):
>
> return A && B || C && D;
>
>is semantically equivalent to
>
> return (A && B) || (C && D);
>
>according to the Java language spec. The && operator is stronger than ||, so
>the extra brackets don't change the semantics.
>
>Admittedly, the explicit brackets make the expression easier to read,
>though, so I've changed the code accordingly. We use explicit brackets in
>similar cases too, so this also makes sense for consistency.
>
>Juergen
>
>
>-----Original Message-----
>From: spr...@li...
>[mailto:spr...@li...]On Behalf
>Of Martin Kersten
>Sent: Friday, February 25, 2005 10:58 PM
>To: spr...@li...
>Subject: [Springframework-developer] Is BeanUtils.isAssignable correct?
>
>
>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)
>
>
>-------------------------------------------------------
>SF email is sponsored by - The IT Product Guide
>Read honest & candid reviews on hundreds of IT Products from real users.
>Discover which products truly live up to the hype. Start reading now.
>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
>
>-------------------------------------------------------
>SF email is sponsored by - The IT Product Guide
>Read honest & candid reviews on hundreds of IT Products from real users.
>Discover which products truly live up to the hype. Start reading now.
>http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
>_______________________________________________
>Springframework-developer mailing list
>Spr...@li...
>https://lists.sourceforge.net/lists/listinfo/springframework-developer
>
>
|