In the previous post, JADEx introduced a new feature Immutability.
Through community feedback, several confusions and limitations were identified.

In v0.42, we have addressed these issues and improved the feature. This post explains the key improvements and new additions in this release.


Improvements

apply immutability -> apply readonly

  • The previous term (Immutability) caused misunderstandings.
  • Community feedback revealed that “Immutable” was interpreted differently by different developers, either as Deeply Immutable or Shallowly Immutable.
  • In v0.42, we replaced it with readonly.
  • Meaning: clearly indicates final by default, preventing reassignment of variables.

Expanded Scope of final keyword: now includes method parameters

  • v0.41: final was applied only to fields + local variables
  • v0.42: final is applied to fields + local variables + method parameters
  • Method parameters are now readonly by default, preventing accidental reassignment inside methods.

Example Code

JADEx Source Code

package jadex.example;

apply readonly;

public class Readonly {

    private int capacity = 2; // readonly
    private String? msg = "readonly"; // readonly

    private int uninitializedCapacity; // error (uninitialized readonly)
    private String uninitializedMsg;    // error (uninitialized readonly)

    private mutable String? mutableMsg = "mutable";  // mutable

    public static void printMessages(String? mutableParam, String? readonlyParam) {

        mutableParam = "try to change"; // error
        readonlyParam = "try to change"; // error

        System.out.println("mutableParam: " + mutableParam);
        System.out.println("readonlyParam: " + readonlyParam);
    }

    public static void main(String[] args) {
        var readonly = new Readonly();
        String? mutableMsg = "changed mutable";

        readonly.capacity = 10; // error
        readonly.msg = "new readonly"; // error

        readonly.mutableMsg = mutableMsg;

        printMessages(readonly.msg, mutableMsg);

        System.out.println("mutableMsg: " + readonly.mutableMsg);
        System.out.println("capacity: " + readonly.capacity);
        System.out.println("msg: " + readonly.msg);
    }
}

Generated Java Code

package jadex.example;

import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import jadex.runtime.SafeAccess;

//apply readonly;

@NullMarked
public class Readonly {

    private final int capacity = 2; // readonly
    private final @Nullable String msg = "readonly"; // readonly

    private final int uninitializedCapacity; // error (uninitilaized readonly)
    private final String uninitializedMsg; // error (uninitilaized readonly)

    private @Nullable String mutableMsg = "mutable";  // mutable

    public static void printMessages(final @Nullable String mutableParam, final @Nullable String readonlyParam) {

        mutableParam = "try to change"; //error
        readonlyParam = "try to change"; //error

        System.out.println("mutableParam: " + mutableParam);
        System.out.println("readonlyParam: " + readonlyParam);
    }

    public static void main(final String[] args) {
        final var readonly = new Readonly();
        final @Nullable String mutableMsg = "changed mutable";

        readonly.capacity = 10; //error
        readonly.msg = "new readonly"; //error

        readonly.mutableMsg = mutableMsg;

        printMessages(readonly.msg, mutableMsg);

        System.out.println("mutableMsg: " + readonly.mutableMsg);
        System.out.println("capacity: " + readonly.capacity);
        System.out.println("msg: " + readonly.msg);
    }
}

New Additions

JSpecify @NullMarked Annotation Support

  • All Java code generated by JADEx now includes the @NullMarked annotation.
  • This improves Null-Safety along with readonly enforcement.

This feature is available starting from JADEx v0.42. Since the IntelliJ Plugin for JADEx v0.42 has not yet been published on the JetBrains Marketplace, if you wish to try it, please download the JADEx IntelliJ Plugin from the link below and install it manually.

JADEx v0.42 IntelliJ Plugin

We highly welcome your feedback on JADEx.

Thank you.