On 31 October 2012 16:09, Greg Thomas <[email protected]> wrote:
> On 31 October 2012 15:51, Dennis Putnam <[email protected]> wrote:
>> I am making my first foray into CompositeConfiguration and am struggling
>> with some basics. I am trying to create a method that returns a specified
>> property or 'null' if it does not exist:
>>
>> Public String getProperty(String prop) {
>> return((String) config.getProperty(prop));
>> }
>
> You can't cast null objects.
This is not directly relevant, but yes, you can cast null to any
object type, because any object type can be null.
> Using the same API call, you can re-write the method as
>
> Public String getProperty(String prop) {
> Object val = config.getProperty(prop);
> if( val == null ) {
> return null;
> } else {
> return (String)val;
> }
> }
>
> However, that's a lesson in Java. More practically, why not simply
> call getString(prop); - that returns a String directly.
>
> Greg
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]