문제

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