ant build java generics,ANT编译泛型

用ant编译java项目的,报泛型错误,但eclipse却没有报错;报错如下:

ScopeUtil.java:185: type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds boolean,java.lang.Object

代码如下 : 

public static final boolean isSuperAdmin() {
   return getSession(key_SuperAdmin);
}

@SuppressWarnings(“unchecked”)
public static final <T> T getSession(String name) {
ActionContext actionContext = ActionContext.getContext();
Map<String, Object> session = actionContext.getSession();
return (T) session.get(name);
}

经过分析,发现isSuperAdmin返回是boolean而getSession,返回是Boolean,既返回对象与返回类型的区别,所以在ant编译时出错;

把代码改一下就可以了:

public static final boolean isSuperAdmin() {
Boolean superAdmin = getSession(key_SuperAdmin);
return superAdmin == true;
}

One thought on “ant build java generics,ANT编译泛型”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.