HaxeDoc2

(やまだぃちぅ) #1
1 var n : Null<Int>=null;
2 var a : Int = n;
3 trace(a); // 0 on static platforms

2.2.1 Optional Arguments and Nullability.......................


Optional arguments also have to be accounted for when considering nullability.
In particular, there must be a distinction betweennativeoptional arguments which are not
nullable and Haxe-specific optional arguments which might be. The distinction is made by using
the question-mark optional argument:
1 // x is a native Int (not nullable)
2 function foo(x : Int = 0) {...}
3 // y is Null<Int> (nullable)
4 function bar(?y : Int) {...}
5 // z is also Null<Int>
6 function opt(?z : Int = -1) {...}

Is there a difference
between?y : Intand
y : Nullor
can you even do the
latter? Some more
explanation and ex-
amples with native
optional and Haxe op-
tional arguments and
how they relate to nul-
lability would be nice.


Is there a difference
between?y : Intand
y : Nullor
can you even do the
latter? Some more
explanation and ex-
amples with native
optional and Haxe op-
tional arguments and
how they relate to nul-
lability would be nice.


Trivia: Argument vs. Parameter
In some other programming languages,argumentandparameterare used interchangeably. In
Haxe,argumentis used when referring to methods andparameterrefers toType Parameters
(Section 3.2).

2.3 Class Instance


Similar to many object-oriented languages, classes are the primary data structure for the majority
of programs in Haxe. Each Haxe class has an explicit name, an implied path and zero or more
class fields. Here we will focus on the general structure of classes and their relations, while
please review future leaving the details of class fields forClass Fields(Chapter 4).
tense


please review future
tense The following code example serves as basis for the remainder of this section:


1 class Point {
2 var x : Int;
3 var y : Int;
4 public function new(x,y){
5 this.x = x;
6 this.y = y;
7 }
8 public function toString() {
9 return "Point("+x+","+y+")";
10 }
11 }
Semantically, this class represents a point in discrete 2-dimensional space - but this is not
important here. Let us instead describe the structure:


  • The keywordclassdenotes that we are declaring a class.

  • Pointis the name of the class and could be anything conforming to the rules for type
    identifiers ( 5 ).

Free download pdf