This is a general-purpose answer as I don't generally work with Beans. It's possible BeanUtils should handle this case, but it would surprise me.
An array of Strings is not the same thing as an ArrayList object, despite their similarities. It's generally a poor idea to implicitly convert from one to the other, as there are multiple logical ways that could be done.
You can use
Arrays.asList()
which takes an array and returns a wrapperList
object. Note that it is not anArrayList
, it is instead a fixed-size custom implementation ofList
which directly interfaces with the passed array, meaning no new storage has to be allocated.If instead you really do want an
ArrayList
, you can construct a new one based off theList
object you got, with:ArrayList<String> ls = new ArrayList<String>(Arrays.asList(myArray));
This call does allocate a new storage array, but if you want adjustable-size, you have to accept that O(n) cost.
These two possible choices, both of which are equally valid depending on your use case, are exactly why it would be a poor idea for your bean to implicitly convert an array into a List
- which implementation should it chose? The fast one that throws exceptions if you try to resize it, or the slow one that doesn't?
Wherever possible, be explicit about your type conversions. Despite the verbosity seeming/being obnoxious, this is one of Java's strongest features.