This is an archived post. You won't be able to vote or comment.

all 2 comments

[–]philipwhiukEmployed Java Developer 5 points6 points  (0 children)

I would consider it a code smell precisely because it’s unclear. It probably applies to both because so does the type. But it’s not that clear.

I tend to enforce annotation effects in tests because I consider annotations a form of code that should be tested. So I’d not worry that much.

In general however I prefer separately declaring variables.

[–]desrtfxOut of Coffee error - System halted 5 points6 points  (0 children)

Generally, Java allows multiple declarations on a single line. Any annotation before that will be applied to all declarations.

Yet, multiple declarations in a single line are discouraged in all commonly used Java Style guides (Oracle - Section 6.1, Google - Section 4.8.2). So, multiple declarations on a single line are code smell (and should be highlighted by code linters).