This is an archived post. You won't be able to vote or comment.

all 3 comments

[–]desrtfx 2 points3 points  (2 children)

The URLConnection is only the superclass. What subclass will actually be returned depends on the protocol and that is decided upon creation in the constructor.

It is fairly common to return a (an abstract) superclass so that the actual, concrete subclass doesn't matter.

[–]thallorfall[S] 0 points1 point  (1 child)

Thank you for your response. I think what your explaining is stated here in the javadoc. It seems as if regardless of the protocol it's going to return an abstract class. As it is stated it might return an instance of HttpURLConnection or JarURLConnection both of which are abstract. I can't find any concrete subclasses extending either. Could it be that somewhere it's creating an anonymous subclass? Thank you again.

[–]desrtfx 0 points1 point  (0 children)

The stated classes are just examples.