Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I believe that you can seal an interface by making it and its method(s) private, but that doesn't do us much good because we're talking about using this to build something that looks like an enum (complete with compiler warnings when we fail to address a branch in a type switch). If you only intend to use your "enum" in the package, then the interface isn't sealed in the scope you want to use it. If you want to use the enum outside of your package, then you can't use the private interface at all.

So you can create a "sealed interface" only in the sense that you can't use it at all outside of its defining package, and it won't be sealed inside of its defining package. I can't see a way to build an enum from this in the way the OP described.



Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: