Hi,
Am 12.02.2011 03:20, schrieb Tom McGlynn:
In my opinion the problem with that solution will be, that I cannot
decide what the default implementation of an interface is, but the
original creator.
If I now want to have the default implementation to be a LinkedList,
then I cannot change it, as Oracle/Sun decided once, that it should be
ArrayList.
Okay, you say, then leave it like it is now, and do "new LinkedList()"
everywhere you want a new list.
Fine, but then I have different implementations of my lists, although
there would be a feature to have the same everywhere.
What you need would be a possibility to overwrite the default
implementation, but what happens if someone else (a jar) also wants to
overwrite the default?
This misapprehends the motivation for this enhancement. If I want to
be able to easily get lists of some default type that I know about,
it's straightforward to write a factory method that will provide them
to me.
List x = Util.getDefaultList();
I'd be concerned about an implementation that allowed the construct
List<X> = new List<X>()
to mean one thing in one program and something else in another, so I
wouldn't want to allow users to control this -- especially given they
have the alternative above.
What my suggestion would allow is for a user to say that they are not
interested in the implementation at all and they are leaving it up to
the framework designer. E.g., suppose I update some code and realize
that I'd like to use a TreeList in some location. If my current code
is
List x = new ArrayList();
then I need to think about whether I had some reason for choosing an
ArrayList which perhaps trumps my new desire to use a TreeList.
However if the code was
List x = new List();
then I know that code had previously placed no constraint on the
implementation, so I should feel free to use a TreeList now.
The goal of this enhancement is to enable users to state that any
reasonable implementation of this interface will do and they rely upon
the framework designer to produce such an implementation. Certainly
if I have specific requirements I should pick the implementation, but
I don't think it would be unusual for the person who wrote the
implementions to have good insight as to what might be a good general
purpose implementation.
Regards,
Tom McGlynn