-
Notifications
You must be signed in to change notification settings - Fork 363
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 class inheritors in the same file #29
Comments
This would be a great thing to have. A question though, with this definition:
I would import B with This is what I like about this proposal: it would let the user choose whether sealed class inheritors are visible at the top-level or not. |
You could use |
Terseness. If you have a Currently, I just use a private constructor for |
I have the same problem in funKTionale import org.funktionale.either.Either.Left
import org.funktionale.either.Either.Right
import org.funktionale.option.Option.None |
Now I see your point. I'm glad that this proposal will fix it. |
The proposal says:
Why not just anywhere in the same file (but not a local class, of course)? I see it in the "Questions" section, but what was the reasoning behind the restriction in the first place? |
I can't say I can follow this. Why the same package? |
Perhaps this issue shouldn't have been closed. That said, I'd like to see the following to compile:
The |
@abreslav Well, there is some not-trivial implementations details(about generation synthetic constructors) which was solved for top-level classes but how do it in general is not clear.
Because top-level classes from one file belong to same package. |
Can someone post an example of inheritance with data class please? |
@sthakor1 have you checked the official Kotlin documentation? http://kotlinlang.org/docs/reference/sealed-classes.html |
The feature has been released in Kotlin 1.1, thus I'm closing the KEEP. Do not hesitate to open a YouTrack issue for any additional suggestions. |
There is still not resolved inheritance. Why I cannot inherit my sealed class in other file? |
@GitHubMurt The short answer is that it'd complicate incremental compilation in all build tools because in some cases, the sealed class should be compiled together with all of its subclasses and a build tool must keep track of relation of files to ensure this. It's not impossible though, so if you do need this feature, please report it as a new issue. |
We really need to have the ability to extend from a sealed class in any file outside of the sealed class declaration file. |
Design proposal
The text was updated successfully, but these errors were encountered: