Prev | Current Page 256 | Next

L. McColl-Sylvester and F. Ponticelli

"Professional haXe and Neko"

The function is used in the conventional way:
var l = [1,2,4,8,16]; // l is of type Array < Int >
trace(indexOf(8, l));
That traces 3 or with another kind of array:
var ls = [???A???,???B???,???C???,???D???]; // ls is of type Array < String >
trace(indexOf(???C???, ls));
It traces 2 .
Constraints on Type Parameters
Being generic can be useful; being too generic can be confusing. For this reason, haXe provides a way to
restrict the class parameters to some types only. Constraint parameters use the syntax illustrated in
Figure 5 - 7 .
class Name
access
modifier
multiple constraints for the
same type parameter are
grouped in parenthesis
Figure 5-7
The use of rounded parentheses is mandatory to disambiguate when more than one class parameter is
used. Multiple constraints are usually the combination of one class and one or more interfaces; the type
T must satisfy all of the listed constraints. The type constraints are not limited to classes and can also be
applied to type parameters for interfaces, enum s, and typedef s.


Pages:
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268