For further consideration... (original) (raw)
Reinier Zwitserloot reinier at zwitserloot.com
Thu Mar 26 14:01:07 PDT 2009
- Previous message: For further consideration...
- Next message: For further consideration...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Just because something goes wrong in one place is no excuse to let it
happen in another.
--Reinier Zwitserloot Like it? Tip it! http://tipit.to
On Mar 26, 2009, at 21:08, Marek Kozieł wrote:
2009/3/25 Tim Keith <tim.keith at gmail.com>:
I would like to suggest at least leaving out ?[]
The example in the proposal is not very compelling: class Group { Person[] members; // null if no members } class Person { String name; // may be null } final String aMember = g?.members?[0]?.name ?: "nobody"; If members is null you get "nobody" but if members is empty (the logical way to signify "no members") you get ArrayIndexOutOfBoundsException. "array?[...]" is like saying: if array is null treat it like it's an infinitely long array of nulls. "object?.member" is like saying: if object it null, treat it like every field is null and every method returns null. The array analog to that should be that "array?.length" means array == null ? 0 : array.length -- Tim
ArrayIndexOutOfBoundsException is valid because on ArrayList would work it in the same way. -- Pozdrowionka. / Regards. Lasu aka Marek Kozieł http://lasu2string.blogspot.com/
- Previous message: For further consideration...
- Next message: For further consideration...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]