开发者

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")) {
...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜