Skip to content

Commit b075cb7

Browse files
committed
Update to current.
This includes changes for Java 8, and simplified import order rules.
1 parent f15e633 commit b075cb7

File tree

1 file changed

+35
-31
lines changed

1 file changed

+35
-31
lines changed

javaguide.html

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -186,37 +186,21 @@ <h4 id="s3.3.2-import-line-wrapping">3.3.2 No line-wrapping</h4>
186186

187187
<h4 id="s3.3.3-import-ordering-and-spacing">3.3.3 Ordering and spacing</h4>
188188

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>
193190

194191
<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>
205195

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>
211198

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>
213202

214-
<li><code>javax</code> imports</li>
215-
</ol>
216203

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>
220204

221205
<h3 id="s3.4-class-declaration">3.4 Class declaration</h3>
222206

@@ -284,9 +268,15 @@ <h4 id="s4.1.2-blocks-k-r-style">4.1.2 Nonempty blocks: K &amp; R style</h4>
284268
<code class="prettyprint lang-java">else</code> or a comma.</li>
285269
</ul>
286270

287-
<p>Example:</p>
271+
<p>Examples:</p>
272+
273+
<pre class="prettyprint lang-java">return () -&gt; {
274+
while (condition()) {
275+
method();
276+
}
277+
};
288278

289-
<pre class="prettyprint lang-java">return new MyClass() {
279+
return new MyClass() {
290280
@Override public void method() {
291281
if (condition()) {
292282
try {
@@ -381,7 +371,8 @@ <h4 id="s4.5.1-line-wrapping-where-to-break">4.5.1 Where to break</h4>
381371
such as C++ and JavaScript.)
382372
<ul>
383373
<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
385376
(<code class="prettyprint lang-java">&lt;T extends Foo &amp; Bar&gt;</code>), and the pipe in
386377
catch blocks
387378
(<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>
443434
</li><li><em>Optionally</em> before the first member or after the last member of the class (neither
444435
encouraged nor discouraged).</li>
445436

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,
447439
<a href="#s3.3-import-statements">Import statements</a>).</li>
448440
</ol>
449441

@@ -488,6 +480,17 @@ <h4 id="s4.6.2-horizontal-whitespace">4.6.2 Horizontal whitespace</h4>
488480

489481
<li>the colon (<code class="prettyprint lang-java">:</code>) in an enhanced
490482
<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) -&gt; 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>
491494
</ul>
492495
</li>
493496

@@ -690,7 +693,8 @@ <h4 id="s4.8.5-annotations">4.8.5 Annotations</h4>
690693
<pre class="prettyprint lang-java">@Partial @Mock DataLoader loader;
691694
</pre>
692695

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>
694698

695699
<a name="comments"></a>
696700
<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>
729733
recommended by the Java Language Specification:
730734
</p>
731735

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
733737
</pre>
734738

735739
<h4 id="s4.8.8-numeric-literals">4.8.8 Numeric Literals</h4>

0 commit comments

Comments
 (0)