The next version of JOML, which will be 1.9.0, will feature ‘immutable’ views/interfaces on all JOML classes.
This feature was proposed over a year ago and finally made its way into the code base.
For a detailed debate/examination of immutable views, have a look at the mentioned GitHub issue #52.
In summary, it allows an API to communicate/express the intent that a data structure, which it exposes or consumes, should/will not be modified by the consumer and/or by the provider. This is valuable in the way that a consumer of that API will know what to do when given a mutable or immutable data structure, which is most apparent when dealing with mutable instances such as Vector4f or Matrix4f, and with a client not knowing whether it can savely store a reference to this instance or (inefficiently) copy the data structure.
Likewise, it protects the API provider from unintentional modifications made by the API consumer.
Examples:
// API provider:
private Vector4f internal;
public Vector4fc provideImmutable() {
return internal;
}
public void consumeImmutable(Vector4fc constVector) {
// ... constVector will not be modified ...
}
// API client:
Vector4fc providerVector = api.provideImmutable();
// providerVector will not be changed by API consumer
Vector4f clientVector = new Vector4f(...);
api.consumeImmutable(clientVector);
So, it’s all about communicating and to some extent enforcing intention of how a data structure is to be used, and by whom. This in turn improves efficiency and reduces errors in programs due to unclear semantics/intentions.
The release will happen in a few days once final testing is done.
People interested in it, can already use it from oss.sonatype.org as org.joml:joml:1.9.0-SNAPSHOT or from the GitHub repository. The API is stable and also completely backwards source-compatible, meaning that porting an unmodified application from earlier JOML versions to 1.9.0 will compile without changes.