commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dennis Putnam <deput...@cisco.com>
Subject Re: [configuration] Re: CompositeConfiguration Checking Existence of Properties.
Date Wed, 31 Oct 2012 16:16:25 GMT
Thanks for the reply. I had 'getString' originally and got the same 
error so I changed to 'getProperty' thinking that might fix it. Since I 
am not casting when I use 'getString' don't see why I get the same 
error. In any case I will use your suggestion even with 'getString'.

On 10/31/2012 12:09 PM, Greg Thomas 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. 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
>

-- 
*Dennis Putnam*, Systems Administrator
Acquisitions Integration
Data Net IT at Cisco
770-236-6922

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message