PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
Map<String, Object> returnMap = new HashMap<String, Object>();
for (int i = 0; i < propertyDescriptors.length; i++) {
......
returnMap.put(propertyName, result);
}
Map<String, Object> returnMap = new HashMap<String, Object>();
PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < propertyDescriptors.length; i++) {
......
returnMap.put(propertyName, result);
}
which order is better when defining the local var? if define it as the first code, it will make too long distance between propertyDescriptors defined and their use, but defined it as the second code, it will long distance between map defined or map use.
So which is rule to order them ?
It is not different. If having to choose one, i will choose the second. Because i think that you care about the Map more than the PropertyDescriptor and the PropertyDescripor is only used to generate the Map values. So it is a intermediate variable relative to the Map and should be defined where it is used.