Java布尔if语句搞砸了

时间:2013-02-14 23:45:59

标签: java if-statement calendar hashmap boolean

我有这个if语句,当我用JOptionPane.showMessageDialog检查时(如代码顶部所示)返回false,但块仍然执行。我看不出我应该做些什么不同。

变量:

  • c = GregorianCalendar
  • s = String
  • h = HashMap-array - String,Date
  • oldGoods1,2和3 = HashMaps - 字符串,日期

代码:

JOptionPane.showMessageDialog(null, c.after((Date) h[counter].get(s)));
if(c.after((Date) h[counter].get(s))); //this line
{
  Calendar today = Calendar.getInstance();
  if(today.after((Date) h[counter].get(s)))
  {
    GoodsList.removeDate(s, (Date) h[counter].get(s));
  }
  if(!oldGoods1.containsKey(s)) 
  {
    oldGoods1.put(s, (Date) h[counter].get(s));
  }
  else if(!oldGoods2.containsKey(s))
  {
    oldGoods2.put(s, (Date) h[counter].get(s));
  }
  else if(!oldGoods3.containsKey(s))
  {
    oldGoods3.put(s, (Date) h[counter].get(s));
  }
}

事先谢谢 Highace2

1 个答案:

答案 0 :(得分:9)

if(c.after((Date) h[counter].get(s)));  // The `;` is the culprit. Remove it.

if statement的末尾有一个分号,只在那里终止if statement,并且无论条件如何,下面的块只是一个本地块。评估为。