суббота, 24 марта 2012 г.

Lombok annotations at class level

Некоторое время назад, с удивлением узнал, что аннотации @Getter/@Setter из Lombok можно ставить не только на члены класса, но и на сам класс!

Это сделало мой код ещё короче и даже яснее. Сравните сами, как было:

@Entity
@Table(name = "countries")
public class Country {
public static final int NAME_LENGTH = 50;
@Getter
@Setter
@Id
@GeneratedValue
private Integer id;
@Getter
@Setter
@Column(length = NAME_LENGTH, unique = true, nullable = false)
private String name;
@Getter
@Setter
@Column(name = "created_at", nullable = false)
private Date createdAt;
}

и как стало:

@Entity
@Table(name = "countries")
@Getter
@Setter
public class Country {
public static final int NAME_LENGTH = 50;
@Id
@GeneratedValue
private Integer id;
@Column(length = NAME_LENGTH, unique = true, nullable = false)
private String name;
@Column(name = "created_at", nullable = false)
private Date createdAt;
}

Теперь аннотации JPA и Lombok не смешиваются, что делает код более чистым.

Мелочь, а приятно!

Комментариев нет:

Отправить комментарий