init()方法的使用

public AB class{

private  CD cd;
private String ef;
private Date gh;
//init将变量挂到一个地方,以后的方法中多次调用
public void init(CD cd){
 ef = cd.getXX();
gh = cd.getXX();
}

public void methodA(){
 anotherMethod(ef,gh);
}

public void methodB(){
 theOtherMethod(ef,gh);
}


}

以后在用到的时候

步骤1:new 一个类set变量
CD cd = new CD();
cd.setXX();
步骤2:AB对象调用cd
AB.init(cd);
步骤3:AB的对象调用methodA
AB.methodA();
原文地址:https://www.cnblogs.com/lonely-buffoon/p/5618820.html