java_code_style - JasonWayne/personal-wiki GitHub Wiki

Where to Break的问题

当一行含有太多的字符,在哪里换行总是令人纠结。而Google Java Code Style告诉我们:

The prime directive of line-wrapping is: prefer to break at a higher syntactic level. Also: When a line is broken at a non-assignment operator the break comes before the symbol. (Note that this is not the same practice used in Google style for other languages, such as C++ and JavaScript.) This also applies to the following "operator-like" symbols: the dot separator (.), the ampersand in type bounds (<T extends Foo & Bar>), and the pipe in catch blocks (catch (FooException | BarException e)). When a line is broken at an assignment operator the break typically comes after the symbol, but either way is acceptable. This also applies to the "assignment-operator-like" colon in an enhanced for ("foreach") statement. A method or constructor name stays attached to the open parenthesis (() that follows it. A comma (,) stays attached to the token that precedes it.

另外,StackExchange上ceilfors的回答也很明确。

if (ch >= 'a' && ch <= 'z')