gnodet commented on PR #14068:
URL: https://github.com/apache/maven/pull/14068#issuecomment-7014195558

   I want to address the "needless churn" concern directly, because I think the 
framing matters.
   
   Maven 4's `@Immutable` types are value types by design — no setters, no 
mutable state. The natural Java expression for a value type since Java 16 is a 
record. Records use noun-style accessors by definition: `groupId()`, not 
`getGroupId()`. They also define structural equality (`equals`/`hashCode` based 
on components), unlike plain classes which default to object identity.
   
   We don't use records here for concrete Java language reasons:
   
   - The generated model has inheritance chains (`Model extends ModelBase`) — 
records cannot extend classes, and records cannot extend other records either 
(they are implicitly `final` and extend `java.lang.Record`)
   - Request/result types use a builder pattern that records don't natively 
support yet (Project Amber is working on "with expressions", but no JEP has 
shipped)
   
   These are language limitations, not semantic ones. The types *are* value 
types; they just can't *be* records yet.
   
   Records can implement interfaces. If `Artifact` declares `groupId()`, a 
future `record DefaultArtifact(String groupId, ...)` implements it for free — 
the record component satisfies the interface method directly. If the interface 
declares `getGroupId()`, that same record needs an explicit override for every 
field, defeating the purpose entirely. Noun-style now is what makes these 
interfaces record-ready when the language catches up.
   
   The JDK has applied this consistently to every new immutable type since Java 
8 — `Collector`, `HttpResponse`, `ModuleDescriptor`, the entire Classfile API 
(Java 24). The two exceptions are constrained by pre-existing legacy 
hierarchies. This was discussed in detail in #11582.
   
   On stability: I fully agree, which is exactly why these PRs exist *before* 
4.0 GA. As @slachiewicz noted in #14061, we should stabilize the API as early 
as possible. Post-GA, this change becomes a breaking one; pre-GA, it's additive 
and binary-compatible — no method is removed, the existing `getX()` methods are 
retained as `@Deprecated` bridges. Code compiled against any previous 4.0 RC 
continues to work at runtime without recompilation.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to