@@ -186,37 +186,21 @@ <h4 id="s3.3.2-import-line-wrapping">3.3.2 No line-wrapping</h4>
186
186
187
187
< h4 id ="s3.3.3-import-ordering-and-spacing "> 3.3.3 Ordering and spacing</ h4 >
188
188
189
-
190
-
191
- < p > Import statements are divided into the following groups, in this order, with each group
192
- separated by a single blank line:</ p >
189
+ < p > Imports are ordered as follows:</ p >
193
190
194
191
< ol >
195
- < li > All static imports in a single group
196
- < ul >
197
- < li > Static import is not used for static nested classes; these are imported with normal imports
198
- in the appropriate group below.</ li >
199
- </ ul >
200
- </ li >
201
-
202
- < li > < code > com.google</ code > imports
203
- (only if this source file is in the < code > com.google</ code > package
204
- space)</ li >
192
+ < li > All static imports in a single block.</ li >
193
+ < li > All non-static imports in a single block.</ li >
194
+ </ ol >
205
195
206
- < li > Third-party imports, one group per top-level package, in ASCII sort order
207
- < ul >
208
- < li > for example: < code > android</ code > , < code > com</ code > , < code > org</ code > , < code > sun</ code > </ li >
209
- </ ul >
210
- </ li >
196
+ < p > If there are both static and non-static imports, a single blank line separates the two
197
+ blocks. There are no other blank lines between import statements.</ p >
211
198
212
- < li > < code > java</ code > imports</ li >
199
+ < p > Within each block the imported names appear in ASCII sort order. (< strong > Note:</ strong >
200
+ this is not the same as the import < em > statements</ em > being in ASCII sort order, since '.'
201
+ sorts before ';'.)</ p >
213
202
214
- < li > < code > javax</ code > imports</ li >
215
- </ ol >
216
203
217
- < p > Within a group there are no blank lines, and the imported names appear in ASCII sort
218
- order. (< strong > Note:</ strong > this is not the same as the import < em > statements</ em > being in
219
- ASCII sort order; the presence of semicolons warps the result.)</ p >
220
204
221
205
< h3 id ="s3.4-class-declaration "> 3.4 Class declaration</ h3 >
222
206
@@ -284,9 +268,15 @@ <h4 id="s4.1.2-blocks-k-r-style">4.1.2 Nonempty blocks: K & R style</h4>
284
268
< code class ="prettyprint lang-java "> else</ code > or a comma.</ li >
285
269
</ ul >
286
270
287
- < p > Example:</ p >
271
+ < p > Examples:</ p >
272
+
273
+ < pre class ="prettyprint lang-java "> return () -> {
274
+ while (condition()) {
275
+ method();
276
+ }
277
+ };
288
278
289
- < pre class =" prettyprint lang-java " > return new MyClass() {
279
+ return new MyClass() {
290
280
@Override public void method() {
291
281
if (condition()) {
292
282
try {
@@ -381,7 +371,8 @@ <h4 id="s4.5.1-line-wrapping-where-to-break">4.5.1 Where to break</h4>
381
371
such as C++ and JavaScript.)
382
372
< ul >
383
373
< li > This also applies to the following "operator-like" symbols: the dot separator
384
- (< code class ="prettyprint lang-java "> .</ code > ), the ampersand in type bounds
374
+ (< code class ="prettyprint lang-java "> .</ code > ), the two colons of a method reference
375
+ (< code class ="prettyprint lang-java "> ::</ code > ), the ampersand in type bounds
385
376
(< code class ="prettyprint lang-java "> <T extends Foo & Bar></ code > ), and the pipe in
386
377
catch blocks
387
378
(< code class ="prettyprint lang-java "> catch (FooException | BarException e)</ code > ).</ li >
@@ -443,7 +434,8 @@ <h4 id="s4.6.1-vertical-whitespace">4.6.1 Vertical Whitespace</h4>
443
434
</ li > < li > < em > Optionally</ em > before the first member or after the last member of the class (neither
444
435
encouraged nor discouraged).</ li >
445
436
446
- < li > As required by other sections of this document (such as Section 3.3,
437
+ < li > As required by other sections of this document (such as Section 3,
438
+ < a href ="#s3-source-file-structure "> Source file structure</ a > , and Section 3.3,
447
439
< a href ="#s3.3-import-statements "> Import statements</ a > ).</ li >
448
440
</ ol >
449
441
@@ -488,6 +480,17 @@ <h4 id="s4.6.2-horizontal-whitespace">4.6.2 Horizontal whitespace</h4>
488
480
489
481
< li > the colon (< code class ="prettyprint lang-java "> :</ code > ) in an enhanced
490
482
< code class ="prettyprint lang-java "> for</ code > ("foreach") statement</ li >
483
+
484
+ < li > the arrow in a lambda expression:
485
+ < code class ="prettyprint lang-java "> (String str) -> str.length()</ code > </ li >
486
+ </ ul >
487
+ but not
488
+
489
+ < ul >
490
+ < li > the two colons (< code class ="prettyprint lang-java "> ::</ code > ) of a method reference, which
491
+ is written like < code class ="prettyprint lang-java "> Object::toString</ code > </ li >
492
+ < li > the dot separator (< code class ="prettyprint lang-java "> .</ code > ), which is written like
493
+ < code class ="prettyprint lang-java "> object.toString()</ code > </ li >
491
494
</ ul >
492
495
</ li >
493
496
@@ -690,7 +693,8 @@ <h4 id="s4.8.5-annotations">4.8.5 Annotations</h4>
690
693
< pre class ="prettyprint lang-java "> @Partial @Mock DataLoader loader;
691
694
</ pre >
692
695
693
- < p > There are no specific rules for formatting parameter and local variable annotations.</ p >
696
+ < p > There are no specific rules for formatting annotations on parameters, local variables, or types.
697
+ </ p >
694
698
695
699
< a name ="comments "> </ a >
696
700
< h4 id ="s4.8.6-comments "> 4.8.6 Comments</ h4 >
@@ -729,7 +733,7 @@ <h4 id="s4.8.7-modifiers">4.8.7 Modifiers</h4>
729
733
recommended by the Java Language Specification:
730
734
</ p >
731
735
732
- < pre > public protected private abstract static final transient volatile synchronized native strictfp
736
+ < pre > public protected private abstract default static final transient volatile synchronized native strictfp
733
737
</ pre >
734
738
735
739
< h4 id ="s4.8.8-numeric-literals "> 4.8.8 Numeric Literals</ h4 >
0 commit comments