To those who compare enums with .equals() -- moomarc, Sloth
Post MTG Forge Related Programming Questions Here
	Moderators: timmermac, Agetian, friarsol, Blacksmith, KrazyTheFox, CCGHQ Admins
			2 posts
			 • Page 1 of 1
		
	
To those who compare enums with .equals() -- moomarc, Sloth
 by Max mtg » 19 Feb 2013, 02:58
by Max mtg » 19 Feb 2013, 02:58 
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
http://stackoverflow.com/questions/1750 ... -or-equals
			- Code: Select all
- if (sa.getApi().toString().equals("DealDamage")) {
 - and -
 || (!a.getApi().equals(ApiType.Mana) && !a.getApi().equals(ApiType.ManaReflected))) {
- Code: Select all
- if (sa.getApi() == ApiType.DealDamage) {
 - and -
 || (a.getApi() != ApiType.Mana && a.getApi() != ApiType.ManaReflected)) {
http://stackoverflow.com/questions/1750 ... -or-equals
Single class for single responsibility.
		- Max mtg
- Programmer
- Posts: 1997
- Joined: 02 Jul 2011, 14:26
- Has thanked: 173 times
- Been thanked: 334 times
Re: To those who compare enums with .equals() -- moomarc, Sl
 by moomarc » 19 Feb 2013, 05:57
by moomarc » 19 Feb 2013, 05:57 
Thanks Max. I'll keep that in mind in future. 
			
-Marc
		- 
				 
 moomarc
- Pixel Commander
- Posts: 2091
- Joined: 04 Jun 2010, 15:22
- Location: Johannesburg, South Africa
- Has thanked: 371 times
- Been thanked: 372 times
			2 posts
			 • Page 1 of 1
		
	
Who is online
Users browsing this forum: No registered users and 32 guests
