From b5c8ecae344b5697210b9aa9a3ce08b608cea239 Mon Sep 17 00:00:00 2001 From: Kurt Alfred Kluever Date: Thu, 9 Apr 2026 12:35:19 -0400 Subject: [PATCH] 2026 updates to the Java Style Guide. (#968) --- javaguide.html | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/javaguide.html b/javaguide.html index d6f54bf..a3f23a4 100644 --- a/javaguide.html +++ b/javaguide.html @@ -183,7 +183,12 @@ class declaration with a module declaration, but otherwise follows the same stru

3.2 Package declaration

-

The package declaration is not line-wrapped. The column limit (Section 4.4, +

Every source file must have a package declaration. +Compact source files are not used. (This rule obviously does not apply to +module-info.java files, which have a different syntax that does not include a +package declaration.) + +

The package declaration is not line-wrapped. The column limit (Section 4.4, Column limit: 100) does not apply to package declarations.

@@ -194,6 +199,16 @@ class declaration with a module declaration, but otherwise follows the same stru

Wildcard ("on-demand") imports, static or otherwise, are not used.

+

3.3.1.1 No module imports

+ +

+Module imports are not used.

+ +

Example:

+ +
import module java.base;
+
+

3.3.2 No line-wrapping

Imports are not line-wrapped. The column limit (Section 4.4, @@ -855,7 +870,7 @@ package com.example.frozzler;

/** This is a module. */
 @Deprecated
-@SuppressWarnings("CheckReturnValue")
+@SuppressWarnings("CheckReturnValue") // TODO: b/123 - Fix existing CRV violations.
 module com.example.frozzler { ... }
 
@@ -869,8 +884,9 @@ module com.example.frozzler { ... } public String getNameIfPresent() { ... } -

Exception: A single parameterless annotation -may instead appear together with the first line of the signature, for example:

+

Exception: If the method or constructor only has a +single, parameterless annotation, it may appear together with the first +line of the signature, for example:

@Override public int hashCode() { ... }
 
@@ -1111,6 +1127,14 @@ be styled as constants.

FooBarT). +

5.2.9 Unnamed variables

+ +

The _ syntax for unnamed variables and parameters is +allowed wherever it is applicable. For example:

+ +
Predicate<String> alwaysTrue = _ -> true;
+
+

5.3 Camel case: defined

@@ -1232,7 +1256,7 @@ justified is explained in a comment.

try {
   int i = Integer.parseInt(response);
   return handleNumericResponse(i);
-} catch (NumberFormatException ok) {
+} catch (NumberFormatException _) {
   // it's not numeric; that's fine, just continue
 }
 return handleTextResponse(response);