/ Published in: Java
Expand |
Embed | Plain Text
public class MyObj { String s1, s2; this.s1 = s1; this.s2 = s2; } return s1; } return s2; } if (obj == null) { //ak je objekt, s ktorym porovnavam null, tak nemam co porovnavat return false; } if (getClass() != obj.getClass()) { //ak porovnavany objekt "obj" nie je typu MyObj return false; } MyObj other = (MyObj) obj; //pretypujem if ((this.s1 == null) ? (other.s1 != null) : !this.s1.equals(other.s1)) { //asi najzlozitejsi riadok, ale vyzera fakt dobre: ak su s1 v oboch objektoch null, tak sa rovnaju; ak nie su null, tak mozem pouzit //metodu equals (alebo v pripade stringov by bolo asi lepsie pouzit compareTo, ale to je jedno...) return false; } return true; } }
You need to login to post a comment.
