r/learnjava • • Feb 05 '26

is this a valid way

So I'm curious about how to use record, because record are immutable and suitable for DTO. I tried to combine it with class, like this

public class UserDto {
    public record ReqRegister() {
    }
    public record ReqLogin() {
    }
    public record ResUser() {
    }
    public record ResLogin() {
    }
}

I think this is readable and easy to maintain, and reduces the number of files, so what do you suggest?

1 Upvotes

13 comments sorted by

View all comments

Show parent comment

1

u/0b0101011001001011 Feb 05 '26

Ah I read too quickly. You're right.