On 21-01-2011 15:55, Jeff Johnson wrote:
> "mp"<(E-Mail Removed)> wrote in message
> news:ihcp10$3d6$(E-Mail Removed)...
>
>> Argument '1': cannot convert from
>> 'System.Collections.Generic.List<Investments.Model.Stock>' to
>> 'System.Collections.Generic.List<Investments.Model.Investment>'
>>
>> but a Stock Is an Investment so i don't know why I can't make that cast?
>
> I JUST happened to read a nice analogy for this a couple of hours ago, so
> let me share the link. (It's a Java tutorial, but the concepts are the
> same.)
>
> http://download.oracle.com/javase/tu...subtyping.html
>
> Read the part about "cages" in the second half.
ArrayList<Investment> lst = new ArrayList<Stock>();
will not compile in Java, but:
ArrayList<? extends Investment> lst = new ArrayList<Stock>();
actually compiles in Java.
(in this particular form it is rather useless, but it can
have its usage)
Arne