Search code examples
javahttpurlurlconnection

Set new object equal to otherObject.method()?


I'm learning java and come across something which confuses me quite a bit. I'm watching a video on an explanation of how http requests work...

URL theURL = new URL("http://www.google.com");
**URLConnection theConn = theURL.openConnection();**

I understand the first line in that it is just creating a URL object with an actual url as an argument. But I don't understand how in the second line, a URLConnection object is being created and being set equal to a method of the other object, or is that method returning something?


Solution

  • The method is returning a URLConnection as documented by the URL.openConnection() Javadoc which says (in part)

    Returns a URLConnection instance that represents a connection to the remote object referred to by the URL.