Skip to content

Instantly share code, notes, and snippets.

View Kira9204's full-sized avatar

Erik Welander Kira9204

View GitHub Profile
@Kira9204
Kira9204 / gist:f55ad07dab58c5fa354e04e04bffe049
Last active September 3, 2024 08:32
@nonull checks Java Jakarta vs Lombok
The `@NotNull` annotation from Jakarta Bean Validation (formerly Javax Validation) and the `@NonNull` annotation from Lombok serve similar but distinct purposes in Java development. Here's a breakdown of the key differences:
### 1. **Purpose and Usage**
- **Jakarta `@NotNull`**:
- **Purpose**: It is a validation constraint used primarily in Java EE or Spring applications to enforce that a particular field or method parameter should not be `null`.
- **Usage**: Typically used on fields, method parameters, or method return types. It is part of the Bean Validation API, which means it's used in contexts where objects are validated, such as when data is being processed by a framework like Spring or Hibernate.
- **Effect**: Triggers a validation error if the annotated element is `null`, often used in combination with a validation framework that checks these constraints at runtime.
```java