2010-07-15 72 views
1

我想知道如何使用反射生成多種類型的方法。 實施例:使用反射生成多種方法

class A() { 

public void CoreMethod1() { 

} 

public void CoreMethod2() { 

} 

// .. 20 such core methods 

public void Method1() { 
    //some initializations 
    //call to CoreMethod1(); 
} 


public void Method2() { 
    //some initializations 
    //call to CoreMethod2(); 
} 

// i need 20 such methods which will call their respective CoreMethods 

//Method1(),Method2() are similar except for their call to the core method. i.e Every respective method will call its coremethod. Ex : Method1() -> CoreMethod1(), Method2() -> CoreMethod2() 
} 

我的問題,我可以生成方法1(),方法2(),方法3()..動態調用各自的核心的方法。有沒有更好的方法來完成這件事?

回答