为什么java.net.HttpURLConnection成为sun.net.www.protocol.http.HttpURLConnection?

时间:2017-08-13 03:37:21

标签: java

我有这样的代码:

HttpURLConnection connection = (HttpURLConnection) loginUrl.openConnection();
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71 Safari/537.36");
connection.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8");
connection.setRequestProperty("Accept-Language", "zh-CN,zh;q=0.8");
connection.setRequestProperty("Connection", "keep-alive");
connection.setRequestProperty("Referer", "http://www.icourse163.org/member/logout.htm");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setDoOutput(true);

OutputStream out = connection.getOutputStream();

我的连接是HttpURLConnection的一个实例,但是当我调试代码时。当代码运行到OutputStream out = connection.getOutputStream();时,我看到getOutputStream()sun.net.www.protocol.http.HttpURLConnection的方法。为什么?

1 个答案:

答案 0 :(得分:3)

因为java.net.HttpURLConnection是一个抽象类,而sun.net.www.protocol.http.HttpURLConnection是它在Oracle JRE中的实现。