Anonymous user
Constrained genericity: Difference between revisions
→{{header|Julia}}
mNo edit summary |
|||
Line 680:
=={{header|Julia}}==
{{works with|Julia|0.6}}
Julia allows user defined types with inheritance. Misuse of a type generally produces a compile time error message.
<lang julia>abstract type Edible end
eat(::Edible) = "Yum!"
mutable struct FoodBox{T<:Edible}
food::
end
variety::
end
end
b = Brick(125.0)
eat(c)
eat(b)</lang>▼
▲carrot = Carrot("Baby")
{{out}}
<pre>MethodError: no method matching eat(::Brick)
Closest candidates are:
eat(!Matched::Edible) at console:2</pre>
▲</lang>
=={{header|Kotlin}}==
|