Illegal class literal for the type parameter T错误解决方法
出现错误的代码如下:
public class ModServiceFinderImpl<Module> extends BaseFinderImpl<Module> implements ModServiceFinder<Module>{public PageView<Module> findByModid(String modid, int pageNo, int pageSize ) {PageView<Module> pv = new PageView<Module>();if(modid != null && !"".equals(modid)) {pv = super.findByPage(Module.class,"from Module m where m.isShow=1 and m.parent.mod_id=" + modid, pageNo, pageSize);}else {pv = super.findByPage(Module.class, "from Module m where m.isShow=1",pageNo, pageSize);}return pv;}}
public class ModServiceFinderImpl extends BaseFinderImpl<Module> implements ModServiceFinder<Module>{public PageView<Module> findByModid(String modid, int pageNo, int pageSize ) {PageView<Module> pv = new PageView<Module>();if(modid != null && !"".equals(modid)) {pv = super.findByPage(Module.class,"from Module m where m.isShow=1 and m.parent.mod_id=" + modid, pageNo, pageSize);}else {pv = super.findByPage(Module.class, "from Module m where m.isShow=1",pageNo, pageSize);}return pv;}}
Example:public class MyGenericClass<T> { public void doSomething() { // Snip... // Call to a 3rd party lib T bean = (T)someObject.create(T.class); // Snip... }}
public class MyGenericClass<T> { private final Class<T> clazz; public static <U> MyGenericClass<U> createMyGeneric(Class<U> clazz) { return new MyGenericClass<U>(clazz); } protected MyGenericClass(Class<T> clazz) { this.clazz = clazz; } public void doSomething() { T instance = clazz.newInstance(); }}