Skip to content

[FEATURE] Static constructors for records #3223

@SerhiiNahornyi

Description

@SerhiiNahornyi

This one is very useful for teams that migrated
from combination of @AllArgsConstructor(staticName = "of") and @Value or used @Value(staticConstructor = "of")
and now starts the migration for records

Right now using of @AllArgsConstructor(staticName = "of") and @RequiredArgsConstructor(staticName = "of")
generates an error is only supported on a class or an enum
Both of these cases will look good in IDEA but will fail in compile stage

    @AllArgsConstructor(staticName = "of")
    public record Person(String name, Integer age){}

    public static void main(String[] args) {
        Person.of();
    }
    @RequiredArgsConstructor(staticName = "of")
    public record Person(String name, Integer age){}

    public static void main(String[] args) {
        Person.of();
    }

Another interesting thing is why IDEA resolves empty methods on allArgs)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions