Hi Oliver, Oliver Heger wrote:
> Hi Jörg, > > Am 28.04.2016 um 16:34 schrieb Jörg Schaible: >> Chas Honton wrote: >> >>> Try casting Object[] to long[]. The compiler and the runtime will >>> complain. >> >> It is not about a cast, it's about returning the proper object. And it >> has nothing to do with primitives, because you cannot cast e.g. Object[] >> to String[] either. > > my first idea was the generic version, too. However, as Chas said, it is > not possible to make a method with such a signature return an array of > primitives. After type erasure, you have > > public Object[] toArray(Class cls, String key) > > and a primitive array is not an Object[]. The question is, why do we have getArray at all? These calls should be completely valid: String[] strArray = conf.get(String[].class, "strings"); Integer[] integerArray = conf.get(Integer[].class, "integers"); int[] intArray = conf.get(int[].class, "ints"); ... and I have implemented something like this in the past. Method getArray should be deprecated immediately. Especially if it is not possible to use it in a type-safe way. Cheers, Jörg --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@commons.apache.org For additional commands, e-mail: user-h...@commons.apache.org