各位大佬,我無意中查看源碼的時候產生如下疑問: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
提交
取消
