7 Replies Latest reply: Mar 9, 2010 11:05 AM by 843793 RSS

    (Class<Map<String, String>>) Map.class -> Cannot cast (certainly!)

    843793
      Hello all,

      tried to search for this topic, but by "class AND generic" you find a lot, but not what you are searching for...

      Here's the problem:
      There's this Mapping-Framework "Dozer" (http://dozer.sourceforge.net/), and you can extend the class "DozerConverter":
      public abstract class DozerConverter<A, B> implements ConfigurableCustomConverter {
        // ...
        public DozerConverter(Class<A> prototypeA, Class<B> prototypeB) {
          this.prototypeA = prototypeA;
          this.prototypeB = prototypeB;
        }
        // ...
      }
      Now I want to write a converter that converts a Map<String, String> to an Object (don't blame me for that - there's this old crappy code and I got to deal with it). My problem is how to call the super-class:
      public class MyMapObjectConverter extends DozerConverter<Map<String, String>, Object> {
          // ...
          public MyMapObjectConverter() {
      
              super((Class<Map<String, String>>) Map.class, Object.class); // doesn't work
      
              // super(Map.class, Object.class); // doesn't work either
              // super(Map<String, String>.class, Object.class); // doesn't work either
          }
          // ...
      }
      I'm a bit clueless at the moment. How to call the super-constructor in a valid way?

      Thank you very much for any hint!

      Best regards
      lotk