Re: [configuration2]: AbstractConfiguration::getArray

2016-04-28 Thread Oliver Heger
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[].

Oliver

> 
>>
>>> On Apr 27, 2016, at 11:59 PM, Jörg Schaible
>>>  wrote:
>>>
>>> Hi Oliver,
>>>
>>> Oliver Heger wrote:
>>>
 Hi Rainer,

> Am 27.04.2016 um 21:22 schrieb Rainer Hirschmiller:
> Hi.
>
> I wonder why AbstractConfiguration::getArray(cls, key) returns a single
> object, not an array of objects? Can somebody explain why the caller
> have to make an explicit cast?
>
> e.g.
> AbstractConfiguration  = ;
>
> Object obj = configuration.getArray(String.class, "key);
> // expected Object[] obj = configuration.getArray(String.class, "key);

 the explanation can be found in the Javadocs of the ConversionHandler
 interface which is used behind the scenes. Citing from the docs of the
 toArray() method:

 "Note that the result type of this method is Object; because this method
 can also produce arrays of a primitive type the return type Object[]
 cannot be used."
>>>
>>> That does not explain, why the method is not declared using generics:
>>>
>>>  public  T[] toArray(Class cls, String key);
>>>
>>> Cheers,
>>> Jörg
>>>
>>>
>>> -
>>> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
>>> For additional commands, e-mail: user-h...@commons.apache.org
>>>
> 
> 
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
> 

-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [configuration2]: AbstractConfiguration::getArray

2016-04-28 Thread 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.

> 
>> On Apr 27, 2016, at 11:59 PM, Jörg Schaible
>>  wrote:
>> 
>> Hi Oliver,
>> 
>> Oliver Heger wrote:
>> 
>>> Hi Rainer,
>>> 
 Am 27.04.2016 um 21:22 schrieb Rainer Hirschmiller:
 Hi.
 
 I wonder why AbstractConfiguration::getArray(cls, key) returns a single
 object, not an array of objects? Can somebody explain why the caller
 have to make an explicit cast?
 
 e.g.
 AbstractConfiguration  = ;
 
 Object obj = configuration.getArray(String.class, "key);
 // expected Object[] obj = configuration.getArray(String.class, "key);
>>> 
>>> the explanation can be found in the Javadocs of the ConversionHandler
>>> interface which is used behind the scenes. Citing from the docs of the
>>> toArray() method:
>>> 
>>> "Note that the result type of this method is Object; because this method
>>> can also produce arrays of a primitive type the return type Object[]
>>> cannot be used."
>> 
>> That does not explain, why the method is not declared using generics:
>> 
>>  public  T[] toArray(Class cls, String key);
>> 
>> Cheers,
>> Jörg
>> 
>> 
>> -
>> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
>> For additional commands, e-mail: user-h...@commons.apache.org
>>



-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [configuration2]: AbstractConfiguration::getArray

2016-04-28 Thread Chas Honton
Try casting Object[] to long[]. The compiler and the runtime will complain. 

> On Apr 27, 2016, at 11:59 PM, Jörg Schaible  
> wrote:
> 
> Hi Oliver,
> 
> Oliver Heger wrote:
> 
>> Hi Rainer,
>> 
>>> Am 27.04.2016 um 21:22 schrieb Rainer Hirschmiller:
>>> Hi.
>>> 
>>> I wonder why AbstractConfiguration::getArray(cls, key) returns a single
>>> object, not an array of objects? Can somebody explain why the caller
>>> have to make an explicit cast?
>>> 
>>> e.g.
>>> AbstractConfiguration  = ;
>>> 
>>> Object obj = configuration.getArray(String.class, "key);
>>> // expected Object[] obj = configuration.getArray(String.class, "key);
>> 
>> the explanation can be found in the Javadocs of the ConversionHandler
>> interface which is used behind the scenes. Citing from the docs of the
>> toArray() method:
>> 
>> "Note that the result type of this method is Object; because this method
>> can also produce arrays of a primitive type the return type Object[]
>> cannot be used."
> 
> That does not explain, why the method is not declared using generics:
> 
>  public  T[] toArray(Class cls, String key);
> 
> Cheers,
> Jörg
> 
> 
> -
> To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
> For additional commands, e-mail: user-h...@commons.apache.org
> 


-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org



Re: [configuration2]: AbstractConfiguration::getArray

2016-04-28 Thread Jörg Schaible
Hi Oliver,

Oliver Heger wrote:

> Hi Rainer,
> 
> Am 27.04.2016 um 21:22 schrieb Rainer Hirschmiller:
>> Hi.
>> 
>> I wonder why AbstractConfiguration::getArray(cls, key) returns a single
>> object, not an array of objects? Can somebody explain why the caller
>> have to make an explicit cast?
>> 
>> e.g.
>> AbstractConfiguration  = ;
>> 
>> Object obj = configuration.getArray(String.class, "key);
>> // expected Object[] obj = configuration.getArray(String.class, "key);
>> 
> 
> the explanation can be found in the Javadocs of the ConversionHandler
> interface which is used behind the scenes. Citing from the docs of the
> toArray() method:
> 
> "Note that the result type of this method is Object; because this method
> can also produce arrays of a primitive type the return type Object[]
> cannot be used."

That does not explain, why the method is not declared using generics:

  public  T[] toArray(Class cls, String key);

Cheers,
Jörg


-
To unsubscribe, e-mail: user-unsubscr...@commons.apache.org
For additional commands, e-mail: user-h...@commons.apache.org