Skip to content
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

String comparison using 'equals' #7

Open
Zot201 opened this issue Sep 3, 2014 · 2 comments
Open

String comparison using 'equals' #7

Zot201 opened this issue Sep 3, 2014 · 2 comments

Comments

@Zot201
Copy link

Zot201 commented Sep 3, 2014

Strings in Java are not guaranteed to share same references even if they have the same contents. You will occasionally get a negative result when comparing identical strings with the identity operator.

A better way to compare strings would be using the 'equals' method. There are some examples using it:

Before:

  1. damageType == "arrow"
  2. damageType != "player"

After:

  1. damageType.equals("arrow")
  2. !damageType.equals("player")

Switching '==' and '!=' to the corresponding 'equals' comparison would help you to reduce non-intentional behaviour in your mod. I have been testing compatibility of my mod to yours. And found that sometimes it does not work due to the usage of reference equality.

@DemoXinMC
Copy link
Owner

Thanks a lot for all the issues you've submitted, I really appreciate the guidance. I've actually learned quite a bit since most of this code was creating, and 1.4 is going to have all of these fixes implemented, most of them having been corrected in code already. This repository is out-of-date very much so at this point, as I haven't seen a point in updating non-compilable code, but rest assured that these, along with other issues are being resolved.

@Zot201
Copy link
Author

Zot201 commented Sep 3, 2014

Glad to hear it honestly. Looking forward to see your work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants