假设我们有这个类
动物.java
public class Animal {
private String name;
private String owner;
private String breed;
}
MainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StringBuilder sb = new StringBuilder();
for(Field f : Animal.class.getDeclaredFields()){
sb.append(f.getName()).append(", ");
}
((TextView) findViewById(R.id.textView1)).setText(sb.toString());
}
}
为什么 TextView 给我的字段没有声明的顺序?(名称,所有者,品种)输出是:品种,名称,所有者