How can I add a secondary constructor to a Value Object (annotaded with @Data) in XTend (XText)?

I have tried the following, but it doesnt compile:

@Data class Dependency {
    val String groupId;
    val String artifactId;
    val String version;
    val String scope;

    new(String groupId, String artifactId, String version) {
        this(groupId, artifactId, version, null)
    }
} 
有帮助吗?

解决方案

That's currently not possible. If there's already a constructor defined, the @Data annotation does not create a new one. You could use an custom Active Annotation to tailor the data class to your needs.

其他提示

Althought technically not a constructor, you can create factory methods to instantiate your data class in multiple ways.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top