This content has been marked as final. Show 2 replies
You would have to persuade the getDeclaredField() method to return something which implements Comparable. Which of course it can't, since there's no guarantee that the string you pass is the name of a field which implements Comparable. So you're stuck casting. Then if you pass the name of a field whose type doesn't implement Comparable, you'll get a ClassCastException.
(The fact that ClassCastException is possible is a clear indication that you can't use a generic type parameter to avoid explicit casting in your code.)