Constrained genericity: Difference between revisions

Added Sidef
(Added Sidef)
Line 1,259:
A more extensive discussion on genericity in Scala and some of the constrains
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}}==
2,747

edits