有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java我可以指定要添加到不可变生成类中的注释吗?

我有一些使用不可变(https://immutables.github.io/)的代码,它生成了一个ImmutableEntity类,方法如下:

public static ImmutableEntity of(EntityId id,
                                  Locale language,
                                  String text)) {
  return validate(new EntityMeldung(id, language, text));
}

但要使用MongoDB Pojo,我需要该方法具有如下注释:

@BsonCreator
public static ImmutableEntity of(@BsonProperty("id") EntityId id,
                                  @BsonProperty("language") Locale language,
                                  @BsonProperty("text") String text)) {
  return validate(new ImmutableEntity(id, language, text));
}

Entity接口只定义了一些getter,我宁愿继续让Immutables生成ImmutableEntity类和of()之类的方法

我应该看Annotation Injection


共 (0) 个答案