commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oliver Heger <oliver.he...@oliver-heger.de>
Subject [BeanUtils] Generics for BeanComparator
Date Wed, 16 Oct 2013 19:49:42 GMT
There is another complicated one:

BeanComparator implements Comparator in a way that it compares a given
property of a specific bean class. The actual comparison is handled by
another Comparator stored in a member field.

So I am tempted to transform it to BeanComparator<T, P> where T is the
bean class and P is the type of the property. The internal Comparator
would then be of type <P>.

However, this does not really work out for the following reasons:
- The internal comparator can be passed to the constructor, but this is
optional. If it is not defined, a helper class from [collections] is
used providing a generic Comparator on Comparable objects. How can this
be aligned to the type parameter?
- The value of the property to be compared is obtained using
PropertyUtils which returns an Object. So there is no chance for the
compiler to do type checks. Perhaps we can check manually whether the
value of the property is of the expected type, but this implies that we
have to determine the class of the type parameter at runtime. AFAIK this
is not always possible, e.g. if a subclass is created which does not
have type parameters.

Any ideas?

Thanks
Oliver


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message