title: Error when trying to make a comparator for a given class on a given field
body: <p>I am trying to make a function that re returns a comparator on a field of a class, but I am getting an error when I am trying to get the value of o2, at the line <code>Comparable v2 = (Comparable) field.get(o2);</code>, saying that a lambda parameter cannot be converted to an object. Can someone help?</p>
  
  <pre><code>public Comparator comp(String className, String fieldName) throws Exception {
      Comparator comparator = Comparator.comparing((o1, o2) -&gt; {
          Class aClass = null;
          try {
              aClass = Class.forName(className);
              Field field = aClass.getDeclaredField(fieldName);
              field.setAccessible(true);
              Comparable v1 = (Comparable) field.get(o1);
              Comparable v2 = (Comparable) field.get(o2);
              return v1.compareTo(v2);
          } catch (Exception e) {
              e.printStackTrace();
          }
          return 0;
      });
      return comparator;
  }
  </code></pre>