How to provide static import for some methods using checkstyle?

How to provide static import for some methods using checkstyle?

for instance

I want the following method to be used only from static imports:

import static java.util.Objects.isNull;
import static java.util.Objects.nonNull;

So code like this should not be allowed:

if (Objects.nonNull(varName)) {

Any ideas on how to achieve this with (preferred) standard or non-standard tools?

+4
source share
1 answer

You can disable the line that imports objects:

<module name="RegexpSinglelineJava">
    <!-- Please statically import methods -->
    <property name="format" value="import java.util.Objects;"/>
</module>
+1
source

Source: https://habr.com/ru/post/1664015/


All Articles