Pregunta

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)
    }
} 
¿Fue útil?

Solución

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.

Otros consejos

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top