For further consideration... (original) (raw)
Marek Kozieł develop4lasu at gmail.com
Thu Mar 26 13:08:39 PDT 2009
- Previous message: For further consideration...
- Next message: For further consideration...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 ]