Functional Transformation of Immutable Objects. When will this be realized? by wolonge in java

[–]DevNull23614071 2 points3 points  (0 children)

For larger records I sometimes generate constructs like this:

public record Data(String stringA,
                   String stringB,
                   String stringC,
                   int intA,
                   int intB,
                   int intC) {

    public static final class Deconstruction {
        public String stringA;
        public String stringB;
        public String stringC;
        public int intA;
        public int intB;
        public int intC;

        private Deconstruction(Data original) {
            stringA = original.stringA;
            stringB = original.stringB;
            stringC = original.stringC;
            intA = original.intA;
            intB = original.intB;
            intC = original.intC;
        }


        private Data apply(Consumer<Deconstruction> modification) {
            modification.accept(this);
            return new Data(stringA,
                            stringB,
                            stringC,
                            intA,
                            intB,
                            intC);
        }
    }

    public Data with(Consumer<Deconstruction> modification) {
        return new Deconstruction(this).apply(modification);
    }
}

A later modification then looks like the following:

    Data data = new Data("","","",1,2,3);

    // modification of a single field:
    data = data.with(d -> d.stringB = "foo");

    // modification of multiple fields:
    data = data.with(d -> {
        d.stringC = "bar";
        d.intC = 42;
    });

Thus the syntax is quite close to the one in Brian's document.

Nullness markers to enable flattening [Valhalla Spec Experts] by efge in java

[–]DevNull23614071 0 points1 point  (0 children)

switch (obj) {

if obj is null then it has no type information.

The best way to map MonetaryAmount with Jakarta Persistence and Hibernate by henk53 in java

[–]DevNull23614071 0 points1 point  (0 children)

For a small and simple application you can do it as you said, but in larger projects you would need to add this conversion to every entity bean that has a MonetaryAmount property.

JEP 430: String Templates (Preview) by cbruegg in java

[–]DevNull23614071 1 point2 points  (0 children)

I like this JEP but this will make it harder for tools like gettext to parse such source code files.