Constrained genericity: Difference between revisions

Content added Content deleted
({{omit from|ZX Spectrum Basic}})
Line 334: Line 334:
}</lang>
}</lang>
Similarly a generic method can constrain its type parameters
Similarly a generic method can constrain its type parameters
<lang java5>public <T extends Eatable> void foo(T x) { }</lang>
<lang java5>public <T extends Eatable> void foo(T x) { } // although in this case this is no more useful than just "public void foo(Eatable x)"</lang>
This <code>T</code> does not necessarily have to be defined in the class declaration. Another method may be declared like this:
This <code>T</code> does not necessarily have to be defined in the class declaration. Another method may be declared like this:
<lang java5>public class Test{
<lang java5>public class Test{