关于java 局部内部类的问题
classTalkingClock{/***Startstheclock*@paramintervaltheintervalbetweenmessages(inmilli...
class TalkingClock
{
/**
* Starts the clock
*@param interval the interval between messages(in milliseconds)
*@param beep true if the clock should beep
*/
public void start(int interval,final boolean beep)
{
ActionListener listener=new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
Date now=new Date();
System.out.println("At the tone ,the time is"+now);
if(beep) Toolkit.getDefaultToolkit().beep();
}
};
Timer t=new Timer(interval,listener);
t.start();
}
}
为什么beep加个final,而interval就不加final呢?? 展开
{
/**
* Starts the clock
*@param interval the interval between messages(in milliseconds)
*@param beep true if the clock should beep
*/
public void start(int interval,final boolean beep)
{
ActionListener listener=new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
Date now=new Date();
System.out.println("At the tone ,the time is"+now);
if(beep) Toolkit.getDefaultToolkit().beep();
}
};
Timer t=new Timer(interval,listener);
t.start();
}
}
为什么beep加个final,而interval就不加final呢?? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询