Strange program flow
I'm really puzzled by the following piece of code:
// Get the content text
String contentText = null;
Header contentEncodingHeader = m_httpEntity.getContentEncoding();
final String contentEncodingValue = contentEncodingHeader != null ? contentEncodingHeader.getValue() : ""; // In my example, this is set to "gzip"
if (contentEncodingValue == "")
{
contentText = this.GetResponseContentText(inputStream, charset);
}
else if (contentEncodingValue == "gzip")
{
contentText = this.GetResponseContentText_GZip(inputStream, charset);
}
return contentText;
When I step over the lines of code, it executes in the following order:
1) if (contentEncodingValue == "")
{
3) contentText = this.GetResponseContentText(inputStream, charset);
}
2) else if (contentEncodingValue == "gzip")
{
contentText = this.GetResponseContentText_GZip(inputStream, charset);
}
4) return contentText;
And even stranger still, is it doesn't even enter the GetResponseContentText
开发者_开发技巧function. I really am confused. Can anyone shed any light on this?
Also, if I comment out the if statement, it works fine (goes into the GetResponseContentText_GZip
function).
From string comparison, you would want to use equals
instead of ==
if (contentEncodingValue.equals("")) {
...
}
else if (contentEncodingValue.equals("gzip")) {
...
}
精彩评论