Search code examples
javalombok

Does Lombok's @UtilityClass support static imports? Are you sure it doesn't?


Lombok's doc says @UtilityClass doesn't provide support for static imports:

Due to limitations in javac, currently non-star static imports cannot be used to import stuff from @UtilityClasses; don't static import, or use star imports.

However, I just checked, and it seems to work fine:

@UtilityClass
public class AuthenticationUtils {
    public UUID getClientId(Authentication authentication) {
        return UUID.fromString(authentication.getName());
    }
}
import static by.afinny.apigateway.util.AuthenticationUtils.getClientId;

// more annotations
@RestController
public class CreditCardController {
    @GetMapping
    public ResponseEntity<List<CreditCardDto>> getCreditCards(Authentication authentication) {
        return creditCardClient.getCreditCards(getClientId(authentication));
    }
@WebMvcTest(CreditCardController.class)
class CreditCardControllerTest {
    // tests that pass

Was it fixed? Did the doc mean something else?


Solution

  • It doesn't support static imports indeed. To see that, try running clean and then compile (assuming it's a Maven project)

    enter image description here