Skip to content

Commit 1308095

Browse files
brunoborgesCopilot
andcommitted
Use var in modernCode where type is redundant with RHS
Replace explicit type declarations with var in 5 patterns where the type is already obvious from the right-hand side (factory methods, getInstance, class literals), making the modern examples consistent with the type-inference-with-var pattern. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 1982564 commit 1308095

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

content/datetime/hex-format.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ oldCode: |-
1717
int val = Integer.parseInt(
1818
"FF", 16);
1919
modernCode: |-
20-
HexFormat hex = HexFormat.of()
20+
var hex = HexFormat.of()
2121
.withUpperCase();
2222
String s = hex.toHexDigits(
2323
byteValue);

content/enterprise/jdbc-resultset-vs-jpa-criteria.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ modernCode: |-
3333
3434
public List<User> findActiveAboveAge(
3535
String status, int minAge) {
36-
CriteriaBuilder cb = em.getCriteriaBuilder();
37-
CriteriaQuery<User> cq =
36+
var cb = em.getCriteriaBuilder();
37+
var cq =
3838
cb.createQuery(User.class);
39-
Root<User> root = cq.from(User.class);
39+
var root = cq.from(User.class);
4040
cq.select(root).where(
4141
cb.equal(root.get("status"), status),
4242
cb.greaterThan(root.get("age"), minAge));

content/enterprise/manual-transaction-vs-declarative.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ modernCode: |-
3737
@Transactional
3838
public void transferFunds(Long from, Long to,
3939
BigDecimal amount) {
40-
Account src = em.find(Account.class, from);
41-
Account dst = em.find(Account.class, to);
40+
var src = em.find(Account.class, from);
41+
var dst = em.find(Account.class, to);
4242
src.debit(amount);
4343
dst.credit(amount);
4444
}

content/io/path-of.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ oldCode: |-
1313
Path path = Paths.get("src", "main",
1414
"java", "App.java");
1515
modernCode: |-
16-
Path path = Path.of("src", "main",
16+
var path = Path.of("src", "main",
1717
"java", "App.java");
1818
summary: "Use Path.of() — the modern factory method on the Path interface."
1919
explanation: "Path.of() is a factory method added directly to the Path interface,\

content/security/key-derivation-functions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ oldCode: |-
1818
SecretKey key =
1919
factory.generateSecret(spec);
2020
modernCode: |-
21-
KDF kdf = KDF.getInstance("HKDF-SHA256");
21+
var kdf = KDF.getInstance("HKDF-SHA256");
2222
SecretKey key = kdf.deriveKey(
2323
"AES",
2424
KDF.HKDFParameterSpec

0 commit comments

Comments
 (0)