<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><br>
&gt; In fact why not just use the generics syntax with protocols ?  Anybody implementing a &quot;Generic&quot; Protocol has to specify the types.<br>
</span>That&#39;s a simple solution, but inconvenient:<br>
One use case for placeholders (I don&#39;t use the official name here to propagate an alternative ;-) is when you have a types that depend on a parameter.<br>
I&#39;m to lazy to look up a real example, but Array&lt;Int&gt; is naturally associated with an enumerator for Int — and it is no fun to be forced to include such relationships all over the place.</blockquote></div><br>So in my example with placeholders.</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div style="font-size:12.8px">class GenericCollection&lt;Type&gt;: Collection&lt;Key: Type, Value: Type&gt; </div><div style="font-size:12.8px">{</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">}</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Has already specified the type of the placeholder :) so subclasses don&#39;t need to specify it. <span style="font-size:12.8px">In this example the Key and Value type placeholders are bound to whatever the Type is.</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">So in these examples</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">let items: </span><span style="font-size:12.8px">GenericCollection&lt;Int&gt;</span><span style="font-size:12.8px"> = </span><span style="font-size:12.8px">GenericCollection()</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">or</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">let items: [Int] = []</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">the Key and Value type placeholders would be Ints :) since the generic type is an Int.</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div></div>