Java方法不按规律来运行?

不止鱼 2011-12-12 04:48:56
@Service("importReportDateImpl")
public class ImportReportDateImpl implements IImportReportFacadeDate {

public void addCcdate(String date) {
this.fileDate = date;
int realMonth = 0;
String s1 = fileDate.substring(0, 4);

fileYear = Integer.parseInt(s1);
realMonth = Integer.parseInt(fileDate.substring(4, fileDate.length()));
fileMonth = realMonth - 1;
}

public int getFileYear() {
return fileYear;
}

public int getFileMonth() {
return fileMonth;
}

public String getFileDate() {
return fileDate;
}

private String fileDate = "";
private int fileYear = 0;
private int fileMonth = 0;

}

如上类里面,在调用这个类的方法中的fileYear,fileMonth的时候,值都是0,而不是我在方法addCcdate里面算好的,但是我是先调用的addCcdate方法,再调用get相关方法,而且addCcdate方法在执行中如果打印fileYear,fileMonth,也都是正确值,并不是0,纠结啊
...全文
131 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
ijames 2011-12-13
  • 打赏
  • 举报
回复
引用地址错误,检查一下heap地址
mgz521009 2011-12-12
  • 打赏
  • 举报
回复
[Quote=引用楼主 robert_lizhiqiang 的回复:]
Java code
@Service("importReportDateImpl")
public class ImportReportDateImpl implements IImportReportFacadeDate {

public void addCcdate(String date) {
this.fileDate = date;
int r……
[/Quote]
楼主,你的方法里只有get 没有set 吗? 加个set 不就好了!

把 private String fileDate = "";
private int fileYear = 0;
private int fileMonth = 0;
放在上面,放下面这,好像不是规范吧!
kouyiSC 2011-12-12
  • 打赏
  • 举报
回复
LZ调用有问题。。细心些哈。。。程序不可能出问题。。出问题的永远是使用者。。支配者。。。
游一游走一走 2011-12-12
  • 打赏
  • 举报
回复
程序对的不能再对了,你是不是搞了多个ImportReportDateImpl 对象了
凡人之玲珑 2011-12-12
  • 打赏
  • 举报
回复
他先调用 getFileYear getFileMonth方法的 然后在调用addCcdate 这个方法 自然 会没有结果
fyswords 2011-12-12
  • 打赏
  • 举报
回复
public class test {
public static void main(String[] args)
throws Exception
{
ImportReportDateImpl d=new ImportReportDateImpl();
d.addCcdate("201112");
System.out.println(d.getFileYear());
System.out.println(d.getFileMonth());
}
}


2011
11

没问题啊
凡人之玲珑 2011-12-12
  • 打赏
  • 举报
回复
你怎么调用的 int类型的变量初始值 默认值为0
你没调 addCcdate 这个方法 fileYear,fileMonth这两个变量的值肯定是0 你要先调addCcdate 这个方法 fileYear = Integer.parseInt(s1);
realMonth = Integer.parseInt(fileDate.substring(4, fileDate.length()));
fileMonth = realMonth - 1;
才会执行给fileYear,fileMonth这个两个变量赋值
sunnylyy 2011-12-12
  • 打赏
  • 举报
回复
调用addCcdate等方法的程序写一下

67,515

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧