public class Test1 { private String str; public Test1(String str) { this.str = str; } public void Init() { Test(); ... } public void Test() { String s = this.str; ... } } public class Test2 { public static void Init(String str) { Test(str); ... } public void Test(String str) { String s = this.str; ... } } public class Test3 { private static String str; public static void Init(String str) { this.str = str; Test(); ... } public static void Test() { String s = this.str; ... } } new Test1("x").Init(); Test2.Init("x"); Test3.Init("x");
都太麻烦,不如这样:
public class Test{
private string _str;
public Test(string str){
_str = str;
Init();
}
private void Init(){
//todo
}
public void Do(){
// todo
}
}
Test t = Test("x");
t.Do();
另外,是不是静态,应该是和业务有关的