Search code examples
haxe

What is the purpose of a bare package declaration, and what does it do?


What is the purpose of a bare package declaration, and what does it do? As in:

package;

class Main {
    //...
}

Solution

  • package; communicates that you are so-called "top-level", that means, you are not actually in a package.

    You can leave it out, so this will work too:

    class Main {
        //...
    }
    

    If you are in a package, it is required to define the type path at the top of the file, eg. package foo.bar; (where foo.bar is a folder foo/bar in a source path, defined by -src )

    More info https://haxe.org/manual/type-system-modules-and-paths.html