code: @SuppressWarnings("unchecked")
    public static <BASE, FROM extends BASE, TO extends BASE> Class<TO> uglyCrossCast(Class<FROM> cls, Class<BASE> base) {
      if(!base.isAssignableFrom(cls)) {
        throw cls == null ? new ClassCastException("Attempted to use 'null' as class.") : new ClassCastException(cls.getName() + " is not a superclass of " + base);
      }
      return (Class<TO>) cls;
    }
docs: This class performs an ugly cast, from <code>Class&lt;F&gt;</code> to
  <code>Class&lt;T&gt;</code>, where both F and T need to extend B.
  <p>
  The restrictions are there to avoid misuse of this cast helper.
  <p>
  While this sounds really ugly, the common use case will be something like
  
  <pre>
  BASE = Class&lt;Database&gt;
  FROM = Class&lt;Database&gt;
  TO = Class&lt;Database&lt;V&gt;&gt;
  </pre>
  
  i.e. the main goal is to add missing Generics to the compile time type.
  
  @param <BASE> Base type
  @param <TO> Destination type
  @param <FROM> Source type
  @param cls Class to be cast
  @param base Base class for type checking.
  @return Casted class.