我需要將在Class A
中創建的變量的名稱傳遞給Class B
,所以我可以將一個值放入該變量中(在Class B
)。 但是,在類B中,我不知道該變量的名稱。 的代碼是這樣的:如何從一個類傳遞給另一個變量的名稱(不是值)
A類
public class A {
int valore; // this is the variable, in Class b, I don't know this name!
public void callClassB(){
ClassB.Method(what shoudld i put here?)
}
}
這是B級
public class B {
public void Method(the_Name_Of_TheVariable_I_get){
the_Name_Of_TheVariable_I_get = 5; // i need to do this
}
}
沒有,一個這個。的getClass()是B類,它不具備現場 – njzk2