# Is it compiler error or feature?

**URL:** https://community.haxe.org/t/is-it-compiler-error-or-feature/494
**Category:** Haxe
**Created:** [March 2, 2018, 11:09am UTC](https://community.haxe.org/t/is-it-compiler-error-or-feature/494 "2018-03-02T11:09:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![odanylyshyn](https://community.haxe.org/user_avatar/community.haxe.org/odanylyshyn/32/325_2.png) [@odanylyshyn](https://community.haxe.org/u/odanylyshyn)
#### Post date: [March 2, 2018, 11:09am UTC](https://community.haxe.org/t/is-it-compiler-error-or-feature/494/1 "2018-03-02T11:09:55Z")

</div>

See to code below. Why does access to the private method work in this case?  
In the project that I’m doing, this opportunity to call a private method turned out to be convenient, but I wanted to be sure that this would not be a mistake and would work in the future.

```haxe
class Main {
    public static function main() {
        var a = new A();
        A.test(a); // It works!
    }
}

class A {
    public function new() {}
    
    public static function test(a:A):Void{
        a.f();
    }
    
    private function f():Void{
        trace('f');
    }
}

```

---

<div class="post-metadata">

### Author: ![loudo](https://community.haxe.org/user_avatar/community.haxe.org/loudo/32/109_2.png) [@loudo](https://community.haxe.org/u/loudo)
#### Post date: [March 2, 2018, 11:56am UTC](https://community.haxe.org/t/is-it-compiler-error-or-feature/494/2 "2018-03-02T11:56:43Z")

</div>

`test` method is public and you access the private method `f` from a public method of A (`f` is only accessible from A). I guess it is normal.

---

<div class="post-metadata">

### Author: ![odanylyshyn](https://community.haxe.org/user_avatar/community.haxe.org/odanylyshyn/32/325_2.png) [@odanylyshyn](https://community.haxe.org/u/odanylyshyn)
#### Post date: [March 2, 2018, 2:46pm UTC](https://community.haxe.org/t/is-it-compiler-error-or-feature/494/3 "2018-03-02T14:46:24Z")

</div>

So, in a static function of class A, is it possible to call a private method on an **instance** of the same class A. This will always work?

```haxe
 
class Main {
    public static function main() {
        A.test();
    }
}

class A {
    public function new() {}
    
    public static function test():Void {
        var a = new A();
        // f(); // error
        a.f(); // it works, access to private method
    }
    
    private function f():Void{
        trace('f');
    }
}

class B {
    public static function test():Void {
        var a = new A();
        // a.f(); // error
    }
}

```

---

<div class="post-metadata">

### Author: ![odanylyshyn](https://community.haxe.org/user_avatar/community.haxe.org/odanylyshyn/32/325_2.png) [@odanylyshyn](https://community.haxe.org/u/odanylyshyn)
#### Post date: [March 2, 2018, 3:18pm UTC](https://community.haxe.org/t/is-it-compiler-error-or-feature/494/4 "2018-03-02T15:18:48Z")

</div>

P.S. In Java, this also works. Probably this is the norm. OK.
