Regarding null safe oprators

Lawrence Kesteloot lk at teamten.com
Wed Jul 15 15:39:50 PDT 2009


I think that your code below should throw an NPE. An empty list is not
the same as a null list. But you could argue that a new syntax would
allow it, like "for (Integer i ?: integerList)". (I would vote against
this too, but only for simplicity, not because it's the wrong
behavior.)

Lawrence


On Wed, Jul 15, 2009 at 3:33 PM, Vimil Saju<vimilsaju at yahoo.com> wrote:
> If null-safe operators are going to be a part of JDK-7, is it possible to modify the new 'for loop' syntax so that a null pointer exception is not thrown if the list or array over which the loop iterates is null?
>
> Currently the below code will throw a NPE because integerList is null.
>
> List<Integer> integerList = null;
> for(Integer i: integerList) {
>
> }
>
>
>
>
>



More information about the coin-dev mailing list