[英]Access variable update in inner class from outer class in Java
我已经在外部类中声明了一些变量,并尝试从内部类中获取此变量的值,并在外部类的方法中对该变量进行了一些操作。 我在这里分享我如何通过一些示例代码来做到这一点。 它不起作用, String
值保持为空。 我在犯一些错误,或者实际上不知道该怎么做。 我假设外部类将在内部类中更改时获取变量的更新值。 请帮忙。 我不是一个很好的程序员,因此可能缺少基本知识。 谢谢。
public class ABC
{
private String begin, end;
private SimpleDateFormat fromUser = new SimpleDateFormat("yyyy/MM/dd");
private SimpleDateFormat myFormat = new SimpleDateFormat("yyyy-MM-dd");
// Days in Current Month
public X()
{
new getDate(this).execute();
}
public format(){
String currdate = "2013/06/06"
try {
String reformattedbegin = myFormat.format(fromUser.parse(begin));
String reformattedend = myFormat.format(fromUser.parse(end));
Date begdate = myFormat.parse(reformattedbegin);
Date enddate = myFormat.parse(reformattedend);
Date currentdate = myFormat.parse(currdate);
if(currentdate.after(begdate) && currentdate.before(enddate))
System.out.println(enddate + "" + begindate + "" +currendate);
} catch (ParseException e) {
e.printStackTrace();
}
}
private class getdate
{
begin = "2013/06/05";
end = "2013/06/07"
}
}
我实际上想出了如何使用它。 使用适配器并将外部类作为适配器类可以解决此问题。 抱歉,我没有适当提及代码。 谢谢大家的支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.