list literal gotcha and suggestion
Kai.Kunstmann at combase.de
Wed Oct 7 09:19:10 PDT 2009
Having the compiler decide on the runtime type of an object in
"literal"-disguise with multiple distinct interfaces as potential
results leads to serious confusion -- not to mention the effort to
define the language rules for this confusion.
It get's even uglier with an explicit cast as a "compile-time hint".
Why not use a simple factory method in the first place (with some extra
for the map-entry creation)?
I really don't like the idea of literals as placeholders for
implementations of selected interfaces, especially this ambiguous
one-for-all way. This is supposed to be syntactic sugar!
Am Mittwoch, den 07.10.2009, 15:40 +0200 schrieb Reinier Zwitserloot:
> On 2009/07/10, at 14:40, Rémi Forax wrote:
> > The compiler can also reject that code because it's ambiguous.
> Yes - forcing you to cast it, which makes this syntax rather ugly.
> Neal specifically said that he included this in his "Casts are rarely
> neccessary" statement, but he has yet to show me how you can avoid the
> need for a cast in this situation.
> -- Reinier Zwitserloot
More information about the coin-dev