有没有办法让一个类作为参数然后从该类变量调用一个函数?
(我不知道班级名称,但我知道函数名称)
public void executeFunction(RandomClass class1){
class1.sayHi();
}
答案 0 :(得分:0)
您可以使用反射来执行此操作。例如:
let crab_rate (pound, rate) = (float pound) * rate;
let lobster_rate (pound, rate) = (float pound) * rate;
let convert_func (crab_rate, lobster_rate)= function (first,second ) ->
if crab_rate then (float pound) * rate;
elif lobster_rate (float pound) * rate;
let (crab_rate, lobster_rate) = convert_fun(3.4, 6.8); // $3.8 a pound for crab, $6.8 a pound for lobster.
// 10 being how many pounds i want.
crab_rate10 ;