On Tuesday, June 5, 2012 1:19:52 PM UTC+2, KWright wrote:
>
>
> Here's a thought experiment, I have:
>
> public class Foo { ... }
> public class Bar extends Foo { ... }
> public void doSomething(List<? super Bar!> xs)
>
>
> What would be a valid argument to doSomething?
>
> List<Bar!>
> List<Bar>
> List<Foo!>
> List<Foo>
>
>
Type-wise it's all legal, as both Bar and Foo are equal to or a supertype
of Bar. For the nullity aspect, all types are again fine - the idea is that
I can write any expression of type 'Bar!' into this list and be 'safe'.
That means ? super T! is as accepting as it gets - anything goes.
This isn't that hard; certainly not more difficult than generics (with
super and extends and wildcards and all that).
>
> This is definitely something outside the current spec, so adding it would
> be a mammoth task - possibly the same order of magnitude as both generics
> and annotations.
>
Why would it be a mammoth task? This stuff writes itself; the difficult
footwork has all been done in 1.5 as part of generics.
>
> public String! turtleA() { return turtleB(); }
> public String turtleB() { return turtleC(); }
> public String turtleC() { return ...; }
> ... continue until you run out of turtles ...
>
>
> Every method below the top one now has to be changed to return a String!
> (unless you provide some form of nullity cast). Is this not the essence of
> the midas problem?
>
This is (A) not true (you don't have to change turtleB or turtleC if you
don't want to) and (B) even if it was, not the essence of the midas
problem. If you do change turtleB and turtleC, you have an effect on
subclass implementations of this thing, but NOT on callers - they can go on
as if nothing changed. Contrast this to changing it to Option<T> and that
would actually be very annoying.
--
You received this message because you are subscribed to the Google Groups "Java
Posse" group.
To view this discussion on the web visit
https://groups.google.com/d/msg/javaposse/-/E0lE0_tdsOwJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en.