xtend-contrib
xtend-contrib copied to clipboard
@Buildable does not support inheritance
@Buildable
class A {}
@Buildable
class B extends A {}
Error message:
Name clash: The method build(Procedure1<Builder>) of type B has
the same erasure as build(Procedure1<Builder>) of type A but
does not override it.
One possible solution: the build()
and copy()
static methods could be generated into the nested Builder
class instead of directly into the annotated class.
Value objects and inheritance do not mix well. Through subclassing, clients can break the contract of immutabililty. So other clients of the class can no longer be sure that all instances will really be immutable. Could you tell me a little more about your use case?
The proposed solution would break all existing clients and make the API less convenient in the general case.
Another solution would be to allow changing the name of the "build"-method. That would also be interesting for people who like static imports. In your case you could make it buildA
and buildB
, getting rid of the clash.
A pull request for that feature would be welcome =)