Constrained genericity: Difference between revisions
Content added Content deleted
No edit summary |
|||
Line 915: | Line 915: | ||
nom..nom..nom |
nom..nom..nom |
||
nom..nom..nom</pre> |
nom..nom..nom</pre> |
||
=={{header|Objeck}}== |
|||
All generic 'T' types associated with the FoodBox must implement the 'Eatable' interface. Generic constrains may either be an interface or a sub-classed type. |
|||
<lang objeck>use Collection.Generic; |
|||
interface Eatable { |
|||
method : virtual : Eat() ~ Nil; |
|||
} |
|||
class FoodBox<T : Eatable> { |
|||
food : List<T>; |
|||
} |
|||
class Plum implements Eatable { |
|||
method : Eat() ~ Nil { |
|||
"Yummy Plum!"->PrintLine(); |
|||
} |
|||
} |
|||
class Genericity { |
|||
function : Main(args : String[]) ~ Nil { |
|||
plums : FoodBox<Plum>; |
|||
} |
|||
}</lang> |
|||
=={{header|Nim}}== |
=={{header|Nim}}== |