-
Notifications
You must be signed in to change notification settings - Fork 273
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
Kotlin sealed classes #274
Comments
Would you mind putting together a quick project with this example in it so I can work from it? This seems like something we should be able to handle, and hopefully in a more elegant way. |
@johncarl81 sure! I'm happy to help investigate. |
I've been meaning to add Kotlin collection support as well: #264 |
@johncarl81 here is a sample-repo. |
Great! I'll try to jump on it this evening. |
Thanks again @dcow for the example project. Looks like all the generated classes are being created and the issue is dealing with inheritance when handling Thoughts? |
I haven't had tons of time to mull this over, but my initial impression is that it's okay to not support sub-classes of sealed classes unless the compiler also supports such a scenario. For instance, if class Foo extends either of sealed classes A or B or C, is Foo considered one of the cases for a when clause? I'm guessing it would be? If not, I would expect to need a custom converter if I want to go from sealed -> not-sealed. If you do go the full blown support for inheritance route, then my impression is that you'd want to provide such compatibility as an add on module or a configurable option. That way people concerned with it who are willing to pay the performance penalty and don't like serializable for other reasons can still use this library, but people who really need to eek out the most performance can still be happy with custom converters. From a Kotlin angle, using the |
I just wrote a custom converter for a sealed class. I have something like:
This works fine, but it strikes me as something Parceler could support considering that we could generate the
when
clause at compile time. In Kotlin it's colloquial to use a pattern of sealed base class and sub-classes of different types to associate unrelated data structures into some enumerable form. I'm unsure how or if the Kotlin compiler chooses to optimize a when clause on sealed classes, but I think we'd leave that up to the compiler to decide when or how to do so.I haven't looked into this further. I don't know if you can get all types of a sealed class using
kapt
, but I figure it's worth investigation.The text was updated successfully, but these errors were encountered: