它可能是一個簡單的問題,甚至不可能沒有任何類型的接口(數組,地圖等),但我想知道是否有任何將對象名稱轉換爲字符串的可能性,所以我可以作爲參數傳遞。我有兩個類Paciente和Sintomas與多個對象,我需要作爲參數傳遞給一個函數,但我不想使用數組(它必須是這樣),我不能想出任何其他方式這樣做,而無需手動爲每一個插入一個插入。將字符串轉換爲對象名稱Java
Paciente Paciente1 = new Paciente("001", "Ana Melo", 33, "");
Paciente Paciente2 = new Paciente("002", "Rui Costa", 13, "");
Paciente Paciente3 = new Paciente("003", "Joana Martins", 85, "");
Paciente Paciente4 = new Paciente("004", "Pedro Torres", 53, "");
Paciente Paciente5 = new Paciente("005", "Ana Gomes", 93, "");
Paciente Paciente6 = new Paciente("006", "Jorge Costa", 56, "");
Sintomas Sintoma1 = new Sintomas("001", "febre");
Sintomas Sintoma2 = new Sintomas("001", "dores");
Sintomas Sintoma3 = new Sintomas("001", "machas");
Sintomas Sintoma4 = new Sintomas("002", "febre");
Sintomas Sintoma5 = new Sintomas("002", "manchas");
Sintomas Sintoma6 = new Sintomas("003", "febre");
Sintomas Sintoma7 = new Sintomas("003", "dores");
Sintomas Sintoma8 = new Sintomas("004", "febre");
Sintomas Sintoma9 = new Sintomas("006", "manchas");
Sintomas Sintoma10 = new Sintomas("006", "dores");
// now I would like to pass to a function as argument something like this:
for(int i = 0 ; i < 6 ; i++)
kSession.insert("Paciente"+(i+1));
// instead of making
kSession.insert(Paciente1);
kSession.insert(Paciente2);
kSession.insert(Paciente3);
// and so on.
Paciente和Sintomas的意思是pa西班牙語中的「tient」和「symptoms」,對於那些好奇的人來說。 –
所以你基本上想要eval ...使用數組... – Li357
對象沒有名稱。使用參考。你在找「地圖」嗎? – EJP