{"id":17061229,"url":"https://github.com/kunminx/sealedclass4java","last_synced_at":"2026-03-06T10:05:36.595Z","repository":{"id":58235228,"uuid":"530275608","full_name":"KunMinX/SealedClass4Java","owner":"KunMinX","description":"让 Java 1.8 也能像 Kotlin 一样使用 Sealed Class。Make Java 1.8 use Sealed Class like Kotlin","archived":false,"fork":false,"pushed_at":"2022-08-31T03:11:29.000Z","size":116,"stargazers_count":11,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T18:11:37.926Z","etag":null,"topics":["java","java-8","sealed-class"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KunMinX.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-08-29T15:17:03.000Z","updated_at":"2023-02-24T01:44:36.000Z","dependencies_parsed_at":"2022-08-31T00:40:34.719Z","dependency_job_id":null,"html_url":"https://github.com/KunMinX/SealedClass4Java","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/KunMinX/SealedClass4Java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KunMinX%2FSealedClass4Java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KunMinX%2FSealedClass4Java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KunMinX%2FSealedClass4Java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KunMinX%2FSealedClass4Java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KunMinX","download_url":"https://codeload.github.com/KunMinX/SealedClass4Java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KunMinX%2FSealedClass4Java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30171657,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T07:56:45.623Z","status":"ssl_error","status_checked_at":"2026-03-06T07:55:55.621Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["java","java-8","sealed-class"],"created_at":"2024-10-14T10:46:25.639Z","updated_at":"2026-03-06T10:05:36.577Z","avatar_url":"https://github.com/KunMinX.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"![](https://tva1.sinaimg.cn/large/e6c9d24ely1h5p8lqzj58j21ok0oa41p.jpg)\n\n\u0026nbsp;\n\n研发故事：[《Kotlin Sealed Class 太香了，Java 8 也想用怎么办？》](https://juejin.cn/post/7137571636781252622/)\n\n\u0026nbsp;\n\n## 依赖\n\n项目根目录 build.gradle 添加如下依赖：\n\n```\nallprojects {\n    repositories {\n        // ...\n        maven { url 'https://www.jitpack.io' }\n    }\n}\n```\n\n模块 build.gradle 添加如下依赖：\n\n```groovy\nimplementation 'com.github.KunMinX:SealedClass4Java:1.4.0-beta'\n```\n\n\u0026nbsp;\n\n## 使用说明\n\n1.创建一个接口，添加 SealedClass 注解，且接口名开头 _ 下划线，\n\n```java\n@SealedClass\npublic interface _TestEvent {\n  void resultTest1(String a, int b);\n  void resultTest2(String a, int b, int c);\n}\n```\n\n2.编译即可生成目标类，例如 TestEvent，然后可以像 Kotlin 一样使用该类：\n\n```java\nTestEvent event = TestEvent.ResultTest1(\"textx\");\nswitch (event.id) {\n  case TestEvent.ResultTest1.ID:\n    TestEvent.ResultTest1 event1 = (TestEvent.ResultTest1) event;\n    event1.copy(1);\n    event1.paramA;\n    event1.resultB;\n    break;\n  case TestEvent.ResultTest2.ID:\n    break;\n}\n```\n\n3.进阶使用详见 https://juejin.cn/post/7137571636781252622#heading-2\n\n\u0026nbsp;\n\n## License\n\n```\nCopyright 2019-present KunMinX\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunminx%2Fsealedclass4java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkunminx%2Fsealedclass4java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkunminx%2Fsealedclass4java/lists"}