I have been working with SpringBatch and looking the sourcecode of the class
org.springframework.batch.item.file.transform.BeanWrapperFieldExtractor<T>
And I have found this:
public void setNames(String[] names) {
Assert.notNull(names, "Names must be non-null");
this.names = Arrays.asList(names).toArray(new String[names.length]);
}
- What is the purpose of converting an array into a list into an array again?
- Why not use something like this:
public void setNames(String[] names) {
Assert.notNull(names, "Names must be non-null");
this.names = names; // Simpler and without conversions
}
- Or this to create a new instance isolated:
public void setNames(String[] names) {
Assert.notNull(names, "Names must be non-null");
this.names = names.clone(); //Simpler and create a new instance
}
All answers all welcome.