各位大佬,我无意中查看源码的时候产生如下疑问:java.net.URLConnection类中有一个getHeaderFieldDate方法,如下:@SuppressWarnings("deprecation")public long getHeaderFieldDate(String name, long Default) {
String value = getHeaderField(name); try { return Date.parse(value);
} catch (Exception e) { } return Default;
}该方法中调用了一个getHeaderField方法,如下:public String getHeaderField(String name) { return null;
}getHeaderField方法总是返回null,这是为什么呢?谢谢!
1 回答
慕后森
TA贡献1802条经验 获得超5个赞
/**
* Returns the value of the named header field.
* <p>
* If called on a connection that sets the same header multiple times
* with possibly different values, only the last value is returned.
*
*
* @param name the name of a header field.
* @return the value of the named header field, or {@code null}
* if there is no such field in the header.
*/
public String getHeaderField(String name) { return null;
}事实上这个方法在常见实现类里都有被覆写:

比如常见的 HttpURLConnection 中:
public String getHeaderField(String var1) { try { this.getInputStream();
} catch (IOException var3) {
;
} return this.cachedHeaders != null
? this.filterHeaderField(var1, this.cachedHeaders.findValue(var1))
: this.filterHeaderField(var1, this.responses.findValue(var1));
}添加回答
举报
0/150
提交
取消
