Search code examples
javaurlencodehttp-gethttp-methodgetmethod

What does the ? mean in "format(List<? extends NameValuePair>"


I'm following the indications on this post to create a a parametrized URI for an Http GetMethod (http://some.domain/path?param1=value1&param2=value2) and I ran into a new issue.

I have this code:

List<NameValuePair> params = new ArrayList<NameValuePair>();
...
some code which does: params.add(new BasicNameValuePair(paramName, paramValue));
...
String paramString = URLEncodedUtils.format(params, "utf-8");

However, my Eclipse says that URLEncodeUtils.format does not accept type List<NameValuePair> but only List<? extends NameValuePair>.

I thought this may mean that only a subclass would be accepted (I see no sense in it, though, since NameValuePair is not abstract) but I also tried doing this with no luck:

class NameValuePairExtension extends NameValuePair{}
List<NameValuePairExtension> params = new ArrayList<NameValuePairExtension>();

What does this exactly mean?

EDIT:

Thanks for your quick replies.

A part from the theorical repsonses, I just found the "practical solution": NameValuePair is an Interface, so it format connot work with it, and requires an implementation.

Therefore, the solution is to replace NameValuePair by a BasicNameValuePair, which implements the first one.

However, I still find this "extends" a bit confusing.


Solution

  • Xxx<? extends Yyy> means that Xxx has a generic type parameter that can be whatever you want while it implements interface Yyy (if Yyy is an interface) or extends class Yyy (if Yyy is a class).