dimanche 9 juillet 2017

In Java, how can I generate a templated object from a type name?

I'm trying to create a SpecificDatumReader for a class whose name is passed in as a string. I can create one of these classes, and I can get the Class of this class, but none of these actually allows me to create my templated object.

    String[] classList = conf.getClasslist(eventname);
    decoders = new LinkedList<SpecificDatumReader>();
    for (String className : classList)
    {
        Class<?> eventclass = Class.forName(className);
        Object holder = eventclass.newInstance();
        decoders.add(new SpecificDatumReader<WhatGoesHere?>(eventclass));
    }





Aucun commentaire:

Enregistrer un commentaire