Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fields/objects that don't change Immutable #4171

Merged
merged 7 commits into from
Jul 16, 2020
Merged

Conversation

ghost
Copy link

@ghost ghost commented Jul 15, 2020

Description:

This makes the fields of objects that don't change final it also prevents data-only objects from being mutable. Why does this matter? Mainly because objects with an unchangeable state are automatically thread-safe, and they don't suffer from weird state side effects.

It's worth noting that the thread-safe point only applies to objects containing fields that are 1) all immutable or 2) some that are mutable and the mutable fields aren't publicly accessible.

This is important as many of our tasks run async whilst using these objects.

Some objects simply hold data, and have no reason to be mutable, therefore:

  • WorldCoord - Now an immutable object
  • Coord - Now An immutable object

Also in many methods to reset a map we were using:
myMap = new HashMap<>();
This is not that efficient so it's been corrected to this:
myMap.clear();


  • I have tested this pull request for defects on a server.

By making this pull request, I represent that I have the right to waive copyright and related rights to my contribution, and agree that all copyright and related rights in my contributions are waived, and I acknowledge that the TownyAdvanced organization has the copyright to use and modify my contribution under the Towny License for perpetuity.

@ghost ghost self-assigned this Jul 15, 2020
@LlmDl LlmDl added this to the 0.96.3.0 milestone Jul 16, 2020
@LlmDl LlmDl merged commit 6d3fede into master Jul 16, 2020
@LlmDl LlmDl deleted the refactor/immutables branch July 16, 2020 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants