Constrained genericity: Difference between revisions
Content added Content deleted
(Added Sidef) |
|||
Line 1,259: | Line 1,259: | ||
A more extensive discussion on genericity in Scala and some of the constrains |
A more extensive discussion on genericity in Scala and some of the constrains |
||
that can be imposed can be found on [[Parametric Polymorphism]]. |
that can be imposed can be found on [[Parametric Polymorphism]]. |
||
=={{header|Sidef}}== |
|||
<lang ruby>class FoodBox(*food { .all { .respond_to(:eat) } }) { } |
|||
class Fruit { method eat { ... } } |
|||
class Apple < Fruit { } |
|||
say FoodBox(Fruit(), Apple()).dump #=> FoodBox(food: [Fruit(), Apple()]) |
|||
say FoodBox(Apple(), "foo") #!> ERROR: class `FoodBox` !~ (Apple, String)</lang> |
|||
=={{header|Swift}}== |
=={{header|Swift}}== |