Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
docs: Add sample docs for record
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-JF1FCFM\zzBBc committed Aug 30, 2023
1 parent 5d96079 commit f10b510
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,30 @@ In this case we write the file to `System.out`, but we could also get it as a st

The [Javadoc][javadoc] catalogs the complete JavaPoet API, which we explore below.

### Record

From Java 14, support new type for creating object is Record (`record`)

There is how JavaPoet API support record:

```java
JavaFile javaFile = JavaFile.builder("com.squareup.tacos", TypeSpec
.recordBuilder("Taco")
.addField(FieldSpec.builder(String.class, "name").build())
.addField(FieldSpec.builder(Integer.class, "code").build())
.skipJavaLangImports(true)
.build());
```

Which generates:

```java
package com.squareup.tacos;

record Taco(String name, Integer code) {
}
```

### Code & Control Flow

Most of JavaPoet's API uses plain old immutable Java objects. There's also builders, method chaining
Expand Down

0 comments on commit f10b510

Please sign in to comment.