奇怪的程序流程
我对下面的代码感到非常困惑:
// 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;
当我跨过代码行时,它按以下顺序执行:
1) if (contentEncodingValue == "")
{
3) contentText = this.GetResponseContentText(inputStream, charset);
}
2) else if (contentEncodingValue == "gzip")
{
contentText = this.GetResponseContentText_GZip(inputStream, charset);
}
4) return contentText;
更奇怪的是,它甚至没有进入 GetResponseContentText
函数。我真的很困惑。任何人都可以阐明这一点吗?
另外,如果我注释掉 if 语句,它就可以正常工作(进入 GetResponseContentText_GZip 函数)。
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).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在字符串比较中,您需要使用
equals
而不是==
From string comparison, you would want to use
equals
instead of==