This is because when you use
toArray()
it returns an Object[], which can't be cast to a String[] (even tho the contents are Strings) This is because the toArray method only gets a
List
and not
List<String>
as generics are a source code only thing, and not available at runtime and so it can't determine what type of array to create.
use
toArray(new String[v2.size()]);
which allocates the right kind of array (String[] and of the right size)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…