我有一個方法接收一個字符串數組,我需要創建具有適當名稱的對象。動態創建對象
例如:
public class temp {
public static void main(String[] args){
String[] a=new String[3];
a[0]="first";
a[1]="second";
a[2]="third";
createObjects(a);
}
public static void createObjects(String[] s)
{
//I want to have integers with same names
int s[0],s[1],s[2];
}
}
如果我收到( 「一」, 「二」),我必須創建:
Object one;
Object two;
如果我收到( 「男孩」, 「女孩」),我必須創建:
Object boy;
Object girl;
任何幫助,將不勝感激。
也許您還沒有使用Java中的* collection framework *。 – Lion 2012-07-10 10:57:20
你是什麼意思,「用適當的名字」?你是否試圖創建具有名稱屬性的對象?或者你真的想要叫「第一」,「第二」等類?你試過什麼了? – 2012-07-10 10:57:23
「int」不是一個對象! – doNotCheckMyBlog 2012-07-10 10:57:52