question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Avoid static imports and add the related checkstyle

See original GitHub issue

I think that sometimes the code is not so readable using static imports. An example is here using just sigleton which seems not to be clear coming from Collections but could be a private method in the class. Of course, using an IDE you have all the facilities to get that but it’s not the same while reviewing on GitHub. As mentioned by @tombentley I would propose to avoid using static imports and adding the related checkstyle https://checkstyle.sourceforge.io/config_imports.html#AvoidStaticImport. It’s more a refactoring work.

Of course, it’s possible that my opinion is not commonly shared with the other @strimzi/maintainers so if Tom is ok to stick with static imports, what the others think?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
samuel-hawkercommented, Jun 5, 2020

I think in general static imports should be allowed in test code. Maybe not so in non-test code? with certain ModelUtils exceptions.

1reaction
samuel-hawkercommented, Jun 5, 2020

I quite like allowing static imports for HamCrest matchers as

assertThat(actual, is(expected))

is better than

Matchers.assertThat(actual, Matchers.is(expected))

Since matchers are always nested inside assertThats i see no ambiguity as to which class they came from.

Read more comments on GitHub >

github_iconTop Results From Across the Web

AvoidStaticImportCheck (checkstyle 10.5.0 API)
Checks that there are no static import statements. Rationale: Importing static members can lead to naming conflicts between class' members.
Read more >
What is a good use case for static import of methods?
Use static imports only when you were tempted to "abuse inheritance". In this case, would you have been tempted to have BusinessObject extend...
Read more >
Imports - Checkstyle
Checks that there are no static import statements. Rationale: Importing static members can lead to naming conflicts between class' members. It may lead...
Read more >
checkstyle – Imports
Checks that there are no import statements that use the * notation. Rationale: Importing all classes from a package or static members from...
Read more >
Avoid static imports - Carlos Becker
Importing all of the static members from a class can be particularly harmful to readability; if you need only one or two members,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found