Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39924
| Path | csiph.com!weretis.net!feeder8.news.weretis.net!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Arne Vajhøj <arne@vajhoej.dk> |
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Java record |
| Date | Wed, 1 Mar 2023 20:23:03 -0500 |
| Organization | A noiseless patient Spider |
| Lines | 41 |
| Message-ID | <ttotps$3jto$1@dont-email.me> (permalink) |
| References | <906f5a76-929d-46cb-b5e0-fcc8e4ad4e0en@googlegroups.com> |
| MIME-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| Injection-Date | Thu, 2 Mar 2023 01:23:09 -0000 (UTC) |
| Injection-Info | reader01.eternal-september.org; posting-host="4d1fb28c87946106fd48c03755d64fa6"; logging-data="118712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Q+4k9yMmQ/Dp4m6l2HWpJ/CM57xkE2Ys=" |
| User-Agent | Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 |
| Cancel-Lock | sha1:A9V2lzUa1cbWr4b4Tc2vZR6iPqw= |
| Content-Language | en-US |
| In-Reply-To | <906f5a76-929d-46cb-b5e0-fcc8e4ad4e0en@googlegroups.com> |
| Xref | csiph.com comp.lang.java.programmer:39924 |
Show key headers only | View raw
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