Page 1 of 1

To those who compare enums with .equals() -- moomarc, Sloth

PostPosted: 19 Feb 2013, 02:58
by Max mtg
Dear fellow developers, keep in ming that SpellAbility method getAPI() may return you a null and you'll get a funny NPE with the code you wrote like

Code: Select all
if (sa.getApi().toString().equals("DealDamage")) {

 - and -

|| (!a.getApi().equals(ApiType.Mana) && !a.getApi().equals(ApiType.ManaReflected))) {
the correct way to do it is:
Code: Select all
if (sa.getApi() == ApiType.DealDamage) {

 - and -

|| (a.getApi() != ApiType.Mana && a.getApi() != ApiType.ManaReflected)) {
The internets also consider == a better option:
http://stackoverflow.com/questions/1750 ... -or-equals

Re: To those who compare enums with .equals() -- moomarc, Sl

PostPosted: 19 Feb 2013, 05:57
by moomarc
Thanks Max. I'll keep that in mind in future. :D