-
Notifications
You must be signed in to change notification settings - Fork 814
将 GameJavaVersion 转换为 record #5222
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR converts the GameJavaVersion class from a traditional Java class to a record. The change simplifies the code by leveraging Java records' auto-generated constructors, accessors, equals(), and hashCode() methods.
Changes:
- Converted
GameJavaVersionto a record withcomponentandmajorVersionfields - Updated all usages across the codebase from getter methods (
getMajorVersion(),getComponent()) to record accessor methods (majorVersion(),component()) - Cleaned up imports by expanding wildcard imports to specific imports
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| GameJavaVersion.java | Converted class to record, removed manual constructors/getters, added custom equals/hashCode |
| JavaVersionConstraint.java | Updated method calls to use record accessors, reordered imports |
| MojangJavaRemoteVersion.java | Updated to use majorVersion() accessor |
| MojangJavaDownloadTask.java | Updated to use component() and majorVersion() accessors, expanded wildcard import |
| JavaDownloadDialog.java | Updated to use majorVersion() accessor, expanded wildcard import |
| HMCLJavaRepository.java | Updated to use component() accessor, expanded wildcard imports |
| LauncherHelper.java | Updated to use majorVersion() accessor |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @Override | ||
| public int hashCode() { | ||
| return getMajorVersion(); | ||
| return majorVersion(); | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (!(o instanceof GameJavaVersion)) return false; | ||
| GameJavaVersion that = (GameJavaVersion) o; | ||
| return majorVersion == that.majorVersion; | ||
| return this == o || o instanceof GameJavaVersion that && this.majorVersion == that.majorVersion; | ||
| } |
Copilot
AI
Jan 14, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Custom equals() and hashCode() methods override the record's auto-generated implementations but only use majorVersion, ignoring the component field. This violates the equals/hashCode contract for records and could cause unexpected behavior. If only majorVersion should determine equality, consider removing component from the record or documenting this design decision. Otherwise, remove these custom implementations to use the record's default behavior that considers both fields.
由 IDEA 自动完成,涉及文件有点多