0
我有一個數據模型對象在Java中,如:
class Model {
String name;
String email;
}
我想要做的就是動態地確定什麼屬性我想通過使用像JavaScript對象中的變量來設置;
String field = "name";
// This is what I try to achieve, not the real code.
New Model().field = "according content";
or
New Model()[field] = "according content";
感謝
你可以使用反射 – 2015-03-25 00:47:55
@ScaryWombat感謝您的回覆。你能給我舉一個簡單的例子嗎? – Kuan 2015-03-25 00:48:43
看到我的回答低於 – 2015-03-25 00:50:33