commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sebb <seb...@gmail.com>
Subject Re: [configuration] Re: CompositeConfiguration Checking Existence of Properties.
Date Wed, 31 Oct 2012 20:35:28 GMT
On 31 October 2012 16:09, Greg Thomas <greg.d.thomas@gmail.com> wrote:
> On 31 October 2012 15:51, Dennis Putnam <deputman@cisco.com> 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: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>

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


Mime
View raw message