Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

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

Projects
None yet
2 participants
Contributor

soc commented Jan 21, 2014

No description provided.

Contributor

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?

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.

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);
}
Contributor

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.

Contributor

soc commented Jan 22, 2014

@dicej Fixed.

dicej added a commit that referenced this pull request Jan 22, 2014

Merge pull request #161 from soc/topic/SIOOBE
Add StringIndexOutOfBoundsException and use it in String

@dicej dicej merged commit ed11993 into ReadyTalk:master Jan 22, 2014

1 check passed

default The Travis CI build passed
Details
Member

dicej commented Jan 22, 2014

Thanks, Simon!

dicej added a commit to dicej/avian that referenced this pull request Apr 21, 2014

Merge pull request #161 from soc/topic/SIOOBE
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