Looking at GenericWhitespaceCheck in Checkstyle documentation,
Left angle bracket (
<
):
- should be preceded with whitespace only in generic methods definitions.
- should not be preceded with whitespace when it is precede method name or following type name.
- should not be followed with whitespace in all cases.
Right angle bracket (
>
):
- should not be preceded with whitespace in all cases.
- should be followed with whitespace in almost all cases, except diamond operators and when preceding method name.
I am not sure I fully understand the reasoning behind why <
should not be followed by a space and why >
should not be preceded by one.
In other words, why is Map<String>
the convention over Map < String >
?
Is this only because as the number of parameters and depth increases it, the without spaces version is more readable.
Like, Map<String, List<String>>
is more readable than, Map < String, List < String > >
?
Also, as a general question, are there some repository or guides which explain reasons behind Checkstyle conventions?
(a, b, c(d))
,<a, b, c<d>>
. And you don't just squish everything together. You can put spaces after your commas, instead of<a,b,c<d>>
. – VolubleMap<String, List<String>>
(notice the space after the comma). – ExtravagateCheckstyle
is a development tool to help programmers write Java code that adheres to a coding standard. This is the standard that was assumed and accepted by people. If you wish to, you can disable the feature and add spaces. no one is stopping you and it wouldn't break any functionality. But your peers may not like it :) – DonavonC
its is a standard to doif(null == x)
instead ofif(x == null)
to avoid mistaken assignment by doing,if(x = null)
. Wanted to know if something similar exists here too. – OutrageousC
reference was an example that sometimes there is a reasoning behind conventions that get lost with time. I agree there might be nothing here, which is what the question was about, to know if there is one. – Outrageous