Some notes on Elvis and Other Null-Safe Operators

Mark Mahieu markmahieu at googlemail.com
Sat Apr 18 12:17:07 PDT 2009


On 18 Apr 2009, at 11:33, Stephen Colebourne wrote:

> Mark Mahieu wrote:
>> Which doesn't seem like much of an improvement, to me.  But I keep
>> thinking that, in the context of this proposal, a null-safe form of
>> the foreach loop might not be so bad:
>>
>> 	for (Foo foo :? map?.get(key)) {
>> 		...
>> 	}
>
> I certainly think thats an interesting idea.
>
> However, having a null list is something that rarely comes up in the
> code I write. I think thats because I always return an empty list from
> methods and never null (something that is definitely good practice).

Yes, if I were writing the code I mentioned I would also consider  
using different data structures entirely, such as:

http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/ 
common/collect/Multimap.html

That's not always an option though.  It would certainly be a fairly  
substantial change in my example.


Mark




More information about the coin-dev mailing list