6

I would like to know if there's an equivalent for BeanComparator from Commons BeanUtils which would allow using generics (and also wouldn't rely on Commons Collections).

Alexey Grigorev
  • 2,415
  • 28
  • 47
  • 1
    which version are you using? As of v1.9 the comparator is using generics. – Bivas May 05 '14 at 13:21
  • I assume an older one. Thanks, good news that they finally added generic support. But now with new java 8 lambdas it's maybe a bit late :) – Alexey Grigorev May 06 '14 at 09:55
  • I've done a custom comparator allowing generic, and accept filedName (property) to be sorted, but with some reflection api calls involve. – Wundwin Born Jun 04 '14 at 06:02

1 Answers1

2

The 1.9.x version of commons-beanutils is generics compatible. Just update to the current release version (1.9.2 as of June 2014) and you will have what you desire. http://commons.apache.org/proper/commons-beanutils/apidocs/org/apache/commons/beanutils/BeanComparator.html

You can download it here or use the maven artifacts. http://commons.apache.org/proper/commons-beanutils/

That said, it is generally better to not use this reflection mechanism because the performance hit and loss of control will probably not be worth the minor savings in lines of code.

Aaron Zeckoski
  • 5,016
  • 8
  • 25
  • 48