• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: checking for null Noob question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: checking for null Noob question


  • Subject: Re: checking for null Noob question
  • From: Farrukh Ijaz <email@hidden>
  • Date: Sat, 31 Jul 2010 15:45:57 +0300

Or do the following trick:

if(!"N".equals(this.dueDateType()) {
    return this.dueDateType();
}
return "";

Or failsafe operation:

if(!(this.dueDateType()+"").equals("N")) {
    return this.dueDateType();
}
return "";

But all above are applicable to strings only. For other types, you always need to follow the LTR precedence.

Or use try-catch-finally block. Do the wrong things in try, fix the wrong in catch and use finally for final work. ;)

Farrukh

Sent from my iPad

On 31-Jul-2010, at 3:13 PM, Jérémy DE ROYER <email@hidden> wrote:

> So the answer is :
> - "if the object is null, as, in the second test, your use the method 'equals' on this object (null) > NullPointerException"
>
> On the first test, as you first test if the object is null, you can't have a NullPointerException
>
> Hope this help,
>
> Jérémy
>
> Le 31 juil. 2010 à 14:09, Theodore Petrosky a écrit :
>
>> Yes... I was asking 'Why?' is there a NullPointerException with number 2...
>>
>> Ted
>>
>>
>> --- On Sat, 7/31/10, Jérémy DE ROYER <email@hidden> wrote:
>>
>>> From: Jérémy DE ROYER <email@hidden>
>>> Subject: Re: checking for null Noob question
>>> To: "Theodore Petrosky" <email@hidden>
>>> Cc: email@hidden
>>> Date: Saturday, July 31, 2010, 8:07 AM
>>> I won't do the second one because you
>>> could see a NullPointerException. Is it your question ?
>>>
>>> Jérémy
>>>
>>> Le 31 juil. 2010 à 14:05, Theodore Petrosky a écrit :
>>>
>>>>
>>>> Why does this work:
>>>>
>>>> public String dueDateTypeLetter() {
>>>>
>>>> if (this.dueDateType() == null ||
>>> this.dueDateType().equals("N")) {
>>>> return "";
>>>> }
>>>> return this.dueDateType();
>>>> }
>>>>
>>>> and this doesn't....
>>>>
>>>> public String dueDateTypeLetter() {
>>>>
>>>> if (this.dueDateType().equals("N") ||
>>> this.dueDateType() == null) {
>>>> return "";
>>>> }
>>>> return this.dueDateType();
>>>> }
>>>>
>>>> obviously the difference is the order of checking in
>>> the 'if' statement...
>>>>
>>>> I don't really care that I must check in a specific
>>> order... It just took me time to understand that the order
>>> was important.
>>>>
>>>> Ted
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Do not post admin requests to the list. They will be
>>> ignored.
>>>> Webobjects-dev mailing list      (email@hidden)
>>>> Help/Unsubscribe/Update your Subscription:
>>>>
>>>> This email sent to email@hidden
>>>
>>>
>>
>>
>>
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list      (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Re: checking for null Noob question (From: Theodore Petrosky <email@hidden>)
 >Re: checking for null Noob question (From: Jérémy DE ROYER <email@hidden>)

  • Prev by Date: Re: checking for null Noob question
  • Next by Date: Re: checking for null Noob question
  • Previous by thread: Re: checking for null Noob question
  • Next by thread: Re: checking for null Noob question
  • Index(es):
    • Date
    • Thread