从Java中的外部类访问内部类中的变量更新

时间:2013-06-05 18:11:43

标签: java inner-classes outer-classes

我在外部类中声明了一些变量,并尝试从内部类中获取此变量的值,并在外部类的方法中对此变量执行一些操作。我在这里分享我是如何尝试通过一些示例代码来完成的。它不起作用,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"
      }  
  }

1 个答案:

答案 0 :(得分:0)

我实际上已经弄清楚如何使用它。使用Adapter并将外部类作为适配器类解决了这个问题。对不起,我没有恰当地提到代码。谢谢大家的支持。

相关问题