-
Notifications
You must be signed in to change notification settings - Fork 469
bugfix: Fixed the issue where different ReadSheet objects could not get the correct value when comparing them. #468
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
Conversation
|
Is this PR be related with issue #406 ? Please describe the purpose of this PR in detail. If it is not related with any issues or discussions, we will not be able to merge it. |
Yes. |
|
This issue has already been assigned. To be friendly, please leave a comment on the issue. If the original author does not update it, we will reassign it to you. |
|
I remember that using this annotation directly would cause problems? I'm not sure now, so it's best to provide the corresponding test cases :) |
|
Hi, @softlg BTW, please modify the commit message, and you can refer to other PRs to improve your detailed content, use English for commit messages only. |
done |
|
Please add unit test code to the |
I added relevant test cases, please check if there is anything else that needs to be added. |
psxjoy
left a comment
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.
Run mvn spotless:apply to fix these violations.
| sheet2.setHidden(false); | ||
| sheet2.setVeryHidden(true); | ||
|
|
||
| Assertions.assertEquals(sheet1.hashCode(), sheet2.hashCode()); |
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.
just wonder if what's the impacting by the hashCode(), seems above cases just call twice .
What's the actual scenario in your real case?
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.
ust wonder if what's the impacting by the hashCode(), seems above cases just call twice .
What's the actual scenario in your real case?
Zhège lìzǐ shì kěyǐ zhèngcháng yùnxíng de, jùtǐ kěyǐ kàn yǐxià lìzǐ:
23 / 5,000
This example can be run normally, see the following example:

If @EqualsAndHashCode is not implemented, sheet1 will be obtained directly, but sheet2 and sheet1 are expected to be different objects.
@Test
void testMapWithReadSheet() {
ReadSheet sheet1 = new ReadSheet(1, "Sheet1");
ReadSheet sheet2 = new ReadSheet(0, "Sheet2");
Map<ReadSheet, String> map = new HashMap<>();
map.put(sheet1, "sheet1 Value");
//
ReadSheet sheet3 = new ReadSheet(0, "Sheet2");
map.put(sheet3, "sheet3 Value");
String value = map.get(sheet2);
System.out.println(value);
}When ReadSheet does not implement @EqualsAndHashCode, if sheet3 is not added to the map, the value is the value of sheet2, which is problematic.
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.
Yes, the test case mentioned the equals error. Just wonder if the actual case in file, what will trigger the exception scenario?
done |
psxjoy
left a comment
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.
LGTM

Purpose of the pull request
What's changed?
Checklist