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/notBot000_ Feb 05 '26

That's a good point. To be honest, I hadn't thought of that option. Thank you for your insight.