Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39924
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java record |
| Date | 2023-03-01 20:23 -0500 |
| Organization | A noiseless patient Spider |
| Message-ID | <ttotps$3jto$1@dont-email.me> (permalink) |
| References | <906f5a76-929d-46cb-b5e0-fcc8e4ad4e0en@googlegroups.com> |
On 3/1/2023 2:18 PM, e.d.pro...@gmail.com wrote:
> I just saw they added a new thing called record to Java 16. Is this not a replacement for a DTO or am I missing something?
> I create a DTO class like:
> public class TestDTO {
> private String testField;
> public String getTestField() {
> return this.testField;
> }
> public void setTestField(String test) {
> this.testField = test;
> }
> }
>
> I define a matching record definition like:
> public record TestRecordDTO(String testField) {
>
> }
> In web, we use DTOs on the back end to pass data to and from the
> Javascript/Typescript on the front end. It looks like passing to the
> front end works, now how do we use it as a model to get the user
> input?
Records are just a way to create data classes
with less typing.
You can use them just like the equivalent manually created
data classes.
But there are two caveats:
1) they are immutable (only getter, no setter)
2) the getter does not follow Java bean convention - it is
.xxxx() not .getXxxx()
That may work or may not work with what you need from
your model classes.
Arne
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-01 11:18 -0800
Re: Java record Arne Vajhøj <arne@vajhoej.dk> - 2023-03-01 20:23 -0500
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-02 04:01 -0800
Re: Java record Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2023-03-08 20:33 +0100
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-08 12:14 -0800
Re: Java record Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2023-03-08 21:44 +0100
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-08 12:54 -0800
Re: Java record Arne Vajhøj <arne@vajhoej.dk> - 2023-03-13 10:55 -0400
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-13 08:25 -0700
Re: Java record Jason H <DarthPiriteze@deathstar.gal> - 2023-03-21 18:02 +0000
Re: Java record "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2023-03-22 04:04 -0700
csiph-web