出现错误的代码如下:
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;
}
}
错误信息:Illegal class literal for the type parameter Module
解决方法:将类ModServiceFinderImpl<Module>后的泛型参数去掉
修改后的代码:
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;
}
}
总结:这个问题与网络上得另一个问题相同:
问题:Hi all,
I'm creating a generic class and in one of the methods I need to know the Class of the generic type currently in use. The reason is that one of the method's I call expects this as an argument.
Example:
public class MyGenericClass<T> {
public void doSomething() {
// Snip...
// Call to a 3rd party lib
T bean = (T)someObject.create(T.class);
// Snip...
}
}
Clearly the example above doesn't work and results in the following error: Illegal class literal for the type parameter T.
My question is: does someone know a good alternative or workaround for this?
解决方法:
Still the same problems : Generic informations are erased at runtime, it cannot be recovered. A workaround is to pass the class T in parameter of a static method :
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();
}
}
It's ugly, but it works.
注:对泛型的讲解可产考:
http://www.infoq.com/cn/articles/cf-java-generics
分享到:
相关推荐
AES加密时抛出java.security.InvalidKeyException: Illegal key size or default parameter
在 HP 360 G6 安装 Win 2021 时,illegal opcode 错误可以通过以下方法解决: 1. 删除之前做的 RAID 后重新做 RAID:这可以解决由于 RAID 设置不正确所致的 illegal opcode 错误。 2. 更新 BIOS:这可以解决由于 ...
今日遇到如下错误:java.security.InvalidKeyException: Illegal key size 因为美国法律限制,JAVA默认支持AES 128 Bit 的key, 如果你计划使用 192 Bit 或者 256 Bit key, java complier 会抛出 Illegal key size ...
java.security.InvalidKeyException: Illegal key size 解决方案
本文实例讲述了JS提示:Uncaught SyntaxError: Unexpected token ILLEGAL错误的解决方法。分享给大家供大家参考,具体如下: Uncaught SyntaxError: Unexpected token ILLEGAL 未捕获的语法错误: 意想不到的非法...
解决illegal Key Size jdk7版本
FOR-Loop variable ''''<name>'''' cannot be passed as var parameter FOR循环变量不能作为参数传递 FOR-Loop variable ''''<Name>'''' may be undefined after loop 在循环后的FOR循环变量是不确定的 Function ...
解决办法。 如在加密过程中出现下面异常: java.security.InvalidKeyException:illegal Key Size 请将两个jar文件按下列操作完成: 如果安装了JRE,将两个jar文件放到%JRE_HOME%\lib\security目录下覆盖原来的文件;...
Constructor declaration are just like method declaration, except that they do not have any return type and they use the name of the class. The compiler provides us with a default constructor to the ...
“the emulator is JLink-Clone, the segger software only support orginal segger device” 然后闪退,IDE崩溃关闭! 解决方案: 1.升级压缩包里的固件(该固件将SN修改为默认的-1)。 2.进入J-Link Commander,...
解决方法是检查预处理命令是否正确,确保没有拼写错误。 3. fatal error C1083: Cannot open include file: 'stdi.h': No such file or directory 该错误是由于头文件'stdi.h'不存在或文件路径错误引起的。解决方法...
base64转换遇到问题解决方法很好的解决数据转换问题
在使用CSDK中的ADO.Net驱动,更新Blob, Clob大对象数据时, 发生错误: Illegal attempt to use Text/Byte host variable. 解决方法: 使用GbsConnection的方法GetGbsBlob(), GetGbsClob(), 获得Blob,Clob对象...
The 80x86 MOV Instruction 4.8 - Some Final Comments on the MOV Instructions <br>4.9 Laboratory Exercises 4.9.1 The UCR Standard Library for 80x86 Assembly Language Programmers 4.9.2 ...
复制并覆盖%JAVA_HOME%/jre/lib/security下的local_policy.jar 和 US_export_policy.jar
nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Driver' for property 'driver';...
主要给大家介绍了关于Java replaceAll()方法报错Illegal group reference的解决办法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
mysql数据库和中文支持很不友好,经常见到“Illegal mix of collations for operation”错误,该如何解决呢?下面小编给大家带来了mysql数据库中涉及到哪些字符集及彻底解决中文乱码的解决方案,非常不错,一起看看...
Illegal key size or default parameters错的解决办法