nanohttpd - The string contain "/" can't be compared in android? -
this question has answer here:
- how compare strings in java? 23 answers
i think method displays "ok", in fact displays "fails". method b can correct result "ok".
i'm sure function fi.iki.elonen.nanohttpd.getmimetypeforfile("my.css")
return result "text/css".
i don't understand why method can't correct result. there bugs function fi.iki.elonen.nanohttpd.getmimetypeforfile
?
btw, method c can correct result "ok".
method a
string a="text/css"; string b= fi.iki.elonen.nanohttpd.getmimetypeforfile("my.css"); utility.logerror("b: "+b); if (a==b){ utility.logerror("ok"); }else{ utility.logerror("fails"); }
method b
string a="text/css"; string b= fi.iki.elonen.nanohttpd.getmimetypeforfile("my.css"); utility.logerror("b: "+b); if (a.compareto(b)==0){ utility.logerror("ok"); }else{ utility.logerror("fails"); }
method c
string a="text/css"; string b= "text/css"; utility.logerror("b: "+b); if (a==b){ utility.logerror("ok"); }else{ utility.logerror("fails"); }
method 1
it results "fails" it because actual objects on heap getting compared when use == reference : detailed explanation
method 2
it results in ok , b contain same text(mime type) in them (using compare to)
method 3
it results in ok, expected.