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

Add StringIndexOutOfBoundsException and use it in String #161

Merged
merged 1 commit into from Jan 22, 2014

Conversation

soc
Copy link
Contributor

@soc soc commented Jan 21, 2014

No description provided.

@soc
Copy link
Contributor Author

soc commented Jan 22, 2014

@dicej I don't think this will work that way. Java doesn't narrow the type after an instanceof check automatically, afaik, so o is still considered to be of type Object. Or did I misunderstand something?

@dicej
Copy link
Member

dicej commented Jan 22, 2014

The signature of the method is "public boolean equalsIgnoreCase(String)", which means we (and the compiler, and the VM) already know the argument is a String. The instanceof check is only there because somebody (probably me) cut-and-pasted code from equals(Object) without thinking about it and realizing that check is pointless.

@dicej
Copy link
Member

dicej commented Jan 22, 2014

To further clarify, this is what I'm proposing, with more context:

public boolean equalsIgnoreCase(String o) {
   return this == o || (o.length == length && compareToIgnoreCase(o) == 0);
}

@soc
Copy link
Contributor Author

soc commented Jan 22, 2014

Ouch, sorry. The GitHub diff made it look like the code was inside the equals method. Sorry for the noise. Will fix this.

@soc
Copy link
Contributor Author

soc commented Jan 22, 2014

@dicej Fixed.

dicej added a commit that referenced this pull request Jan 22, 2014
Add StringIndexOutOfBoundsException and use it in String
@dicej dicej merged commit ed11993 into ReadyTalk:master Jan 22, 2014
@dicej
Copy link
Member

dicej commented Jan 22, 2014

Thanks, Simon!

dicej added a commit to dicej/avian that referenced this pull request Apr 21, 2014
Add StringIndexOutOfBoundsException and use it in String
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

Successfully merging this pull request may close these issues.

None yet

2 participants