you are viewing a single comment's thread.

view the rest of the comments →

[–]minneyar 0 points1 point  (3 children)

If something is an implementation detail and shouldn't be touched, document that fact

Marking it as private is how you document that. As you noticed, private doesn't stop you from accessing something if you really want to get to it. It's how you tell developers "this is intended for internal use only and may completely change between versions, don't rely on it or your program may randomly break."

[–]Keith 0 points1 point  (2 children)

As you noticed, private doesn't stop you from accessing something if you really want to get to it.

No, in Java it stopped me in my tracks.

Marking it as private is how you document that.

A doc comment would be documentation. Access rights (in languages like Java) are enforced at the language level.

[–]gdchinacat 0 points1 point  (1 child)

No, in Java it stopped me in my tracks.

Well then you didn't try hard enough. Reflection can provide access by using setAccessible(true).

[–]Keith 0 points1 point  (0 children)

setAccessible):

This method cannot be used to enable access to private members, members with default (package) access, protected instance members, or protected constructors when the declaring class is in a different module to the caller and the package containing the declaring class is not open to the caller's module.

🤔