尝试这样的事情:
public class CodecFactory { final private static Map<String, Class<? extends CodecInterface>> precLibrary; static { precLibrary = new HashMap<String, Class<? extends CodecInterface>>(); precLibrary.put("prec1", Codec1.class); //... } static CodecInterface create(String filename, String precid, String args) throws InstantiationException, IllegalAccessException { Class<? extends CodecInterface> clazz; clazz = precLibrary.get(precid); CodecInterface prec = clazz.newInstance(); prec.setArgs(args); prec.setFilename(filename); return prec; }}


