I am trying to use guava to create a comparable where I only care about a single field of a class (used by a collection for sorting). This field is generic and can take any type. I am using guava's Ordering#onResultOf method to convert the wrapper object into the generic type, and provide a comparable for that type.
I have the following code:
  private static final class Reference<T> { ... }
  ...
  public static <T> Function<Reference<T>, T> referenceToData() {
    return (Function<Reference<T>, T>) ToData.INSTANCE;
  }
  private enum ToData implements Function<Reference<Object>, Object> {
    INSTANCE;
    @Override
    public Object apply(final ComparatorMerger.Reference<Object> input) {
      return input.data;
    }
  }
When I compile the code I get the following error:
[ERROR] ... inconvertible types
[ERROR] found   : Reference.ToData
[ERROR] required: com.google.common.base.Function<Reference<T>,T>
I am not sure how to get the casting to work the way I want it to. Any advice?
 
     
    