Any developers out there coming from ActionScript or Java background like me, the default access modifiers and function return type in Haxe are a bit different. So let’s have a quick look at them in classes, interfaces and externs.
Classes:
- Default access modifier is
private
if none specified. - Default function return value type is
Void
if there is no return expression or if the return expression has no argument.
Interfaces and Externs:
- Default access modifier is
public
. - Specifying return value type is compulsory for functions. Failing so will result in compile time error
Type required for extern classes and interfaces
When implementing the above interface you need to specify public
access modifier to variable count
and function increaseCount
as shown below. Failing so will result in the following compile time errors.
Field count should be public as requested by ITest
Field increaseCount should be public as requested by ITest
.
Interesting fact from the official documentation about protected
:
Haxe has no
protected
keyword like in ActionScript, Java, etc. However, itsprivate
behavior is equal to those language’sprotected
behavior, so in reality Haxe lacks inprivate
behavior.