<p>Am 28.02.2014 12:07 schrieb "Joao Morais" <<a href="mailto:l@joaomorais.com.br">l@joaomorais.com.br</a>>:<br>
><br>
> Em 28/02/14 03:44, Sven Barth escreveu:<br>
><br>
>><br>
>> === code end ===<br>
>><br>
>> Currently this will print:<br>
>><br>
>> === output begin ===<br>
>><br>
>> Bar<br>
>><br>
>> === output end ===<br>
>><br>
>> If the compiler would now naively generate an implementation of TMyGeneric with TMyType then the result would be:<br>
>><br>
>> === output begin ===<br>
>><br>
>> Foo<br>
>><br>
>> === output end ===<br>
>><br>
>> This must not be. So the compiler - while it might generate an implicit TMyType implementation - must not use that implicit implemenation if the type that is specialized with implements non virtual methods itself. This is one of the restrictions.<br>
><br>
><br>
> Ah, now I see. "TGeneric<T: TType>" is quite different from "var T: TType". Afaics the former is a placeholder for another type, the latter is a placeholder for an implementation. Thanks for sharing.</p>
<p>Yes, that's an important difference :)</p>
<p>><br>
><br>
>>>> Addendum: this does not exclude the compiler from trying to optimize<br>
>>>> this if the type parameter is indeed a class type. But this will be<br>
>>>> transparent for the user and will have a few restrictions. It does<br>
>>>> however not change that generics aren't full types.<br>
>>><br>
>>><br>
>>> :/<br>
>>><br>
>>> Maybe in the near (or not so near) future, these two approaches<br>
>>> (templates and generics like in Java) may live together? I mean: is this<br>
>>> technically possible?<br>
>><br>
>><br>
>> FPC/Delphi generics are more templates than generics. Generics are not full types. This will not change.<br>
><br>
><br>
> Got the point. Anyway current (2.6) generics meets about 80% of my needs and 2.8 sounds to meet about 98% =). Thanks for the really great work with generics!</p>
<p>You're welcome. I still have enough work left though ;)</p>
<p>Regards,<br>
Sven</p>