Sweenus / SimplySkills

Other
20 stars 18 forks source link

The instanceof operator was used incorrectly, so it has been fixed. #104

Closed fuku-data closed 4 months ago

fuku-data commented 4 months ago

Hi, I'm interested in what you're creating! I'm sorry that it's not listed in the issue, but I had a quick look at the code and noticed something odd about the use of the instanceof operator, so I fixed it.

I'd appreciate your review, especially the cast part.

Below is an example of the fix. example: if (player instanceof ServerPlayerEntity serverPlayer) {...} -> if (player instanceof ServerPlayerEntity) { ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player }

chronosacaria commented 4 months ago

@fuku-data Hey, mate! Thank you for your concerns and the pull request that you've provided. We appreciate that you saw something you were worried about and tried to fix it. Whilst this is extremely kind of you, there have been convention and internal Java changes that make the method you've suggested no longer necessary.

In Java 16, Pattern Variables were introduced which allows for matching without the conversion step needed in older versions of Java. As such, by changing the second operand of the instanceof operator with a type pattern (as Sweeney has done) one can get the same effect but in a much more readable manner.

Should you wish to learn more about this feature, I suggest he following article from Oracle, which does an amazing job of explaining the change: https://docs.oracle.com/en/java/javase/17/language/pattern-matching-instanceof-operator.html

fuku-data commented 4 months ago

Thank you for pointing that out! I didn't have enough knowledge of Java. I will close this case.