https://www.cnblogs.com/soficircle/p/6598245.html
在新建对象中所有的成员变量是先给定了默认初值的:0,null或者false,
之后再调用的构造函数。(如果变量是由其他函数或者表达式进行赋值的,就在此时进行函数或者表达式赋值(牵扯到其他变量的就使用此时的变量值(0或者null)进行计算))
程序如下:(输出结果为:10和1)
class Test
{
int i;
Test(int i)
{
this.i = i;
}
int j=i+1;
}
public class Exercise
{
public static void main(String[]args)
{
Test t = new Test(10);
System.out.println(t.i); //10
System.out.println(t.j); //1
}
}
所以某线程类可以定义如下成员变量,new该task类的时候会初始化成员变量,从而执行对应的方法。
private Future< ? > future = scheduledExecutor.scheduleAtFixedRate(task, AlarmConstant.DELAY_TIME,
AlarmConstant.DIFF_SOURCE_ALARM_PERIOD, TimeUnit.MILLISECONDS);
public Future< ? > getFuture()
{
return future;
}