New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sealed wither interface? #27
Comments
Yeah - could do. I'll look into it. |
It makes more sense to do this for Java 17 when the early builds come out. We wouldn't want to force people to add |
I can't find the class nameandagebuilder under the next idea because I didn't install a plug-in. How do I deal with this |
NameAndAgeBuider? That's a generated class. This is an annotation processor that generates Java files. No plugin needed. |
Hello, but I compiled and reported errors with idea. He couldn't find the generated class. How to deal with this |
@z1065485649 NameAndAgeBuilder is just an example in the documentation. There is no NameAndAge class in this project. The documentation is showing what the results would be if you had a NameAndAge class. |
If you have errors or problems please create an Github Issue and I'll see if I can help. Post your project somewhere or some example files. |
After investigating this I don't think this is worthwhile. The annotation processor would have to add the permits clause and it would be complicated and not add much value. |
Hi again Jordan I hope you don't mind that I ask you to reopen this "issue". Building systems/good software is IMHO alot about designing the domain model. (I'm a decent Java programmer, but old enough to have appreciated a good old and clever database design :-)) And as records is more about composition than inheritance this ticket would be gold to keep open IMHO. When Java 17 is out we can have another discussion about the reporter's initial proposal. My two cents is that this makes sense. Thanks for your good work and the exciting last days commits :-) /Dan |
I'll re-open for a future enhancement. It's too hard to do this right now. Javapoet doesn't support it all. I played around with hacking it into the code but it's far too ugly. When https://github.com/square/javapoet supports Java 16 features maybe we can add this. |
Is there a way to sidestep this entirely, perhaps, by adding methods matching the record's accessors to the generated interface? This would ostensibly avoid the need for Tweaking the example generated code in the README: public interface With {
String name();
int age();
default NameAndAgeBuilder with() {
return NameAndAgeBuilder.builder(new NameAndAge(name(), age()));
}
default NameAndAge withName(String name) {
return new NameAndAge(name, age());
}
default NameAndAge withAge(int age) {
return new NameAndAge(name(), age);
}
} These methods would be automatically implemented by the record, so no actual change to client code is needed. |
@Twisol Thats less cool, I veto |
Hmm - I didn't think of that! That's interesting. I'll play around with that when I get a chance. |
Its still down the line (Java 17, most likely), but it would be nice to have the
RecordName.With
generated interface be sealed so that only the record can implement itThe text was updated successfully, but these errors were encountered: