Re: IllegalArg vs NullPtr Exceptions
Scott A. Hightower wrote:
If doing nothing were always the right behavior, that's what I would do.
But again, that depends upon the client's rules, which I cannot know in
advance.
If you're saying "client" in the sense of "client code" and not "paying
customer", then you very well can know in advance what the client can and
cannot do with the API you provide.
...But are a null List and an empty List equal?
No. 'null' is equal only to 'null'.
There is a mandate for how any 'List' implementation's 'equals()' should work.
<http://java.sun.com/javase/6/docs/api/java/util/List.html#equals(java.lang.Object)>
If the comparison is by natural order, where does a
null List fit? Or an empty List? Or, for that matter, a List that contains
one or more null elements? If these really have meaning to the client code,
and are not just error byproducts, the client has to define the rules.
What is this alleged "natural order" of 'List's?
Which 'List' precedes which:
List <Color> stuff =
Arrays.asList( Color.GREEN, Color.BLUE, Color.RED );
List <Color> nonse =
Arrays.asList( Color.MAGENTA, Color.ORANGE, Color.RED );
?
How about between these two:
List<?> stuff =
Arrays.asList( "green", "blue", "red" );
List<?> nonse =
Arrays.asList( Color.MAGENTA, Color.ORANGE, Color.RED );
?
--
Lew