# Why does \`@:privateAccess\` exist?

**URL:** https://community.haxe.org/t/why-does-privateaccess-exist/2500
**Category:** Haxe
**Created:** [June 2, 2020, 11:56pm UTC](https://community.haxe.org/t/why-does-privateaccess-exist/2500 "2020-06-02T23:56:09Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Nezteb](https://community.haxe.org/user_avatar/community.haxe.org/nezteb/32/1206_2.png) [@Nezteb](https://community.haxe.org/u/Nezteb)
#### Post date: [June 2, 2020, 11:56pm UTC](https://community.haxe.org/t/why-does-privateaccess-exist/2500/1 "2020-06-02T23:56:09Z")

</div>

I’m still new to Haxe, so maybe this is normal/idiomatic, but I still have to ask: why does Haxe have `@:privateAccess` and other metadata like it?

It seems to break the purpose of the `private` keyword. Even the docs don’t seem to explicitly mention its intended purpose:

- [Visibility - Haxe - The Cross-platform Toolkit](https://haxe.org/manual/class-field-visibility.html)
- [Access Control - Haxe - The Cross-platform Toolkit](https://haxe.org/manual/lf-access-control.html)

If a library author makes a field `private`, it seems like anyone who imports that library can use `@:privateAccess` to access it? Despite the original author’s intent on how their API worked? Or am I misunderstanding?

I ask because I noticed that going from Haxe 4.0.5 to 4.1.1 seemed to break HaxeFlixel despite it being a minor version bump, because OpenFL was using `@:privateAccess` to access a private property:

```
/usr/local/lib/haxe/lib/openfl/8,9,6/src/openfl/display/Stage.hx:1426: characters 46-59 : haxe.CallStack has no field lastException

```

Relevant conversation in the Discord: [https://discordapp.com/channels/162395145352904705/165234904815239168/716184557434699806](https://discordapp.com/channels/162395145352904705/165234904815239168/716184557434699806)

I can see the usefulness in accessing `private` fields, but it seems like it’s more likely to break APIs and prevent semantic versioning from working as intended.

---

<div class="post-metadata">

### Author: ![kevinresol](https://community.haxe.org/user_avatar/community.haxe.org/kevinresol/32/272_2.png) [@kevinresol](https://community.haxe.org/u/kevinresol)
#### Post date: [June 3, 2020, 3:49am UTC](https://community.haxe.org/t/why-does-privateaccess-exist/2500/2 "2020-06-03T03:49:42Z")

</div>

Haxe provides ways to sidestep language restrictions when “you are sure what you are doing”. Like `Dynamic` and other “hack-it” metadata, generally you shouldn’t be using them. But when you need to, you can use them, at your own risk.

---

<div class="post-metadata">

### Author: ![Gama11](https://community.haxe.org/user_avatar/community.haxe.org/gama11/32/7_2.png) [@Gama11](https://community.haxe.org/u/Gama11)
#### Post date: [June 3, 2020, 6:40am UTC](https://community.haxe.org/t/why-does-privateaccess-exist/2500/3 "2020-06-03T06:40:11Z")

</div>

Haxe generally follows the philosophy of “you know what you’re doing”. `@:privateAccess` and friends are actually even pretty harmless compared to what you can do with macros, you can use those to rewrite code in third-party libraries at compile time if you want.

---

<div class="post-metadata">

### Author: ![ibilon](https://community.haxe.org/user_avatar/community.haxe.org/ibilon/32/13_2.png) [@ibilon](https://community.haxe.org/u/ibilon)
#### Post date: [June 3, 2020, 7:36am UTC](https://community.haxe.org/t/why-does-privateaccess-exist/2500/4 "2020-06-03T07:36:44Z")

</div>

In languages without such meta you’d likely use reflection to try and get access, which is even more likely to break.  
But yeah like the others have mentioned, you need to know what you’re doing when doing that.
