commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Thomas <greg.d.tho...@gmail.com>
Subject [configuration] Re: CompositeConfiguration Checking Existence of Properties.
Date Wed, 31 Oct 2012 16:09:13 GMT
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. 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


Mime
View raw message