众所周知,Eclipse是带有自己的编译器的,而且我们一般都是使用这个默认自带的编译器去编译自己的项目。但是这个编译器和Sun的javac是否一致呢?别说,还真有那么一点区别。
这是一个普通的 annotation:
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- public@interfaceAnno{
- publicStringitemName();
- }
下面是一个普通的类,使用了这个 annotation:
- publicclassUseAnno
- {
- @Anno(itemName="test")
- publicvoidtestMethod(){
- //
- }
- }
这两个文件无论是用eclipse还是Sun的javac编译,都不会出错误。下面我们把annotation修改一下:
- @Target(ElementType.METHOD)
- @Retention(RetentionPolicy.RUNTIME)
- @Documented
- public@interfaceAnno{
- publicStringitemName();
- publicIntegerb=newInteger(2);
- }
然后在 eclipse 里编译,正常通过。运行的时候也不会出错误,而且运行时,用反射的方式也能正确地得到 annotation 里定义的那个变量。
但是如果你用 javac 编译呢?就会出现错误,无法编译,提示:
注释 Anno <clinit> 缺少。
关于 clinit ,大家可以 google 一下资料,我查到的资料是 javac 在处理 clinit 的时候有一些 bug,可能上面这种情况就是这个 bug 的表现症状之一了。
(之所以认为它是编译器的 bug,是因为 eclipse 编译后,在 java 环境中可以正确运行。)
所以:
1、如果可以的话,尽量不使用 eclipse 自带的编译器。
2、如果可以的话,使用 Netbeans 应该是正确的选择,毕竟都是出自Sun的手中。
3、养成持续集成的习惯。否则如果到后期,才发现一些特性在 javac 的编译中会有差别,损失可就大了。
---------------------------------------------------------------------------------------------------------------------------------------------
【javac】编译类文件
package com.department;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
@InterceptorInfo(method={"execute"}, before={"busi.trim", "busi.tonull", "busi.checknull", "busi.checknum -k ParentDepID,IsLeef"})
@Service("/dep/addDep")
public class AddDepHandler extends AbstractHandler
{
@Resource(name="departmentDao")
private IDepartmentDao depDao;
protected void execute(BusinessContext context)
throws Exception
{
BusinessResponse response = context.getResponse();
BusinessRequest request = context.getRequest();
Department department = new Department();
String depCode = (String)request.getParams("DepCode");
String depName = (String)request.getParams("DepName");
String parentDepid = (String)request.getParams("ParentDepID");
String isLeef = (String)request.getParams("IsLeef");
department.setFatherID(Integer.valueOf(Integer.parseInt(parentDepid)));
department.setDepCode(depCode);
department.setDepName(depName);
department.setType(Integer.valueOf(isLeef.equals("1") ? 1 : 0));
List deps = this.depDao.getListByFatherId(department.getFatherID());
for (Department dep : deps) {
if (dep == null)
continue;
if ((dep.getDepName() == null) || (dep.getDepCode() == null))
continue;
if ((dep.getDepName().equals(depName)) || (dep.getDepCode().equals(depCode))) {
throw new BusinessException("存在数据");
}
}
Integer id = this.depDao.insert(department);
response.setSuccess(true);
response.setResCode("0000");
response.setParams("depId", id);
response.setParams("depType", isLeef);
}
}
-----------------------------------------------------------------------------------------------------------------
【eclipse】编译类文件
package com.department;
import java.util.Iterator;
import java.util.List;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
@InterceptorInfo(method={"execute"}, before={"busi.trim", "busi.tonull", "busi.checknull", "busi.checknum -k ParentDepID,IsLeef"})
@Service("/dep/addDep")
public class AddDepHandler extends AbstractHandler
{
@Resource(name="departmentDao")
private IDepartmentDao depDao;
protected void execute(BusinessContext paramBusinessContext)
throws Exception
{
BusinessResponse localBusinessResponse = paramBusinessContext.getResponse();
BusinessRequest localBusinessRequest = paramBusinessContext.getRequest();
Department localDepartment = new Department();
String str1 = (String)localBusinessRequest.getParams("DepCode");
String str2 = (String)localBusinessRequest.getParams("DepName");
String str3 = (String)localBusinessRequest.getParams("ParentDepID");
String str4 = (String)localBusinessRequest.getParams("IsLeef");
localDepartment.setFatherID(Integer.valueOf(Integer.parseInt(str3)));
localDepartment.setDepCode(str1);
localDepartment.setDepName(str2);
localDepartment.setType(Integer.valueOf(str4.equals("1") ? 1 : 0));
List localList = this.depDao.getListByFatherId(localDepartment.getFatherID());
for (Iterator localIterator = localList.iterator(); localIterator.hasNext(); ) { localObject = (Department)localIterator.next();
if (localObject == null)
continue;
if ((((Department)localObject).getDepName() == null) || (((Department)localObject).getDepCode() == null))
continue;
if ((((Department)localObject).getDepName().equals(str2)) || (((Department)localObject).getDepCode().equals(str1))) {
throw new BusinessException("存在数据");
}
}
Object localObject = this.depDao.insert(localDepartment);
localBusinessResponse.setSuccess(true);
localBusinessResponse.setResCode("0000");
localBusinessResponse.setParams("depId", localObject);
localBusinessResponse.setParams("depType", str4);
}
}