将 GameJavaVersion 转换为 record#5222
Conversation
There was a problem hiding this comment.
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; | ||
| } |
There was a problem hiding this comment.
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 自动完成,涉及文件有点多