【javac】编译类文件 与 【eclipse】编译类文件 的 差异

众所周知,Eclipse是带有自己的编译器的,而且我们一般都是使用这个默认自带的编译器去编译自己的项目。但是这个编译器和Sun的javac是否一致呢?别说,还真有那么一点区别。

这是一个普通的 annotation:

Java代码
@Target(ElementType.METHOD)
  1. @Retention(RetentionPolicy.RUNTIME)
  2. @Documented
  3. public@interfaceAnno{
  4. publicStringitemName();
  5. }



下面是一个普通的类,使用了这个 annotation:

Java代码 复制代码 收藏代码
  1. publicclassUseAnno
  2. {
  3. @Anno(itemName="test")
  4. publicvoidtestMethod(){
  5. //
  6. }
  7. }



这两个文件无论是用eclipse还是Sun的javac编译,都不会出错误。下面我们把annotation修改一下:

Java代码 复制代码 收藏代码
  1. @Target(ElementType.METHOD)
  2. @Retention(RetentionPolicy.RUNTIME)
  3. @Documented
  4. public@interfaceAnno{
  5. publicStringitemName();
  6. publicIntegerb=newInteger(2);
  7. }



然后在 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);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值