Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>Do I understand this correctly or is it possible to declare the constraint on the interface and to have that constraint realized by the class?</p> </blockquote> <p>Correct. You <em>have</em><sup>1</sup> to declare the constraint on the type parameters for the generic class as well. Just because you named the type parameter in <code>DocumentPrinter&lt;T&gt;</code> to have the same name as the type parameter in <code>IDocumentPrinter&lt;T&gt;</code> does not mean that they are the same types. When you declare</p> <pre><code>public class DocumentPrinter&lt;T&gt; : IDocumentPrinter&lt;T&gt; </code></pre> <p>you are in fact saying to use <code>T</code> that parameterizes <code>DocumentPrinter&lt;T&gt;</code> to parameterize <code>IDocumentPrinter&lt;T&gt;</code> and <em>now</em> they are the same types. But for that to be legal, <code>T</code> from <code>DocumentPrinter&lt;T&gt;</code> has to satisfy all constraints on the type parameter for <code>IDocumentPrinter&lt;T&gt;</code>. Thus, you must explicitly say that <code>T</code> satisfies <code>T : IFooDoc</code>.</p> <p><sup>1</sup>: Apparently I need to state this explicitly. If you don't do something the language specification requires you to do, your code won't compile. The language specification requires that when you parameterize a generic type, the type that you parameterize it with must satisfy all the constraints on that type parameter for that generic type. If you do not, your code won't compile.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload