bugfix: Fixed the issue where different ReadSheet objects could not get the correct value when comparing them.#468
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.
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.
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.
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.
Yes, the test case mentioned the equals error. Just wonder if the actual case in file, what will trigger the exception scenario?
done |

Purpose of the pull request
What's changed?
Checklist