theJava
theJava

Reputation: 15034

What does this type of Object mean?

HttpEntity<?> requestEntity = new HttpEntity<Object>(json, headers);

I have a couple of questions here?

  1. What does the ? mean here. Why have they put <?> instead of <Object>
  2. Why does the HTTPEntity Constructor take <Object> as its type but the Class Reference taking <?> as its type.

Upvotes: 0

Views: 272

Answers (2)

PermGenError
PermGenError

Reputation: 46408

?-- wildcard syntax

HttpEntity<?> requestEntity = new HttpEntity<Object>(json, headers);

`HttpEntity<?>` whose element type matches anything..

Remember that if you try to add Object into requestEntity you'd get a compiler error.

       requestEntity.add(new Object());//compiler error on this line as it expects `?` not an object

read about generics here

Upvotes: 1

Subhrajyoti Majumder
Subhrajyoti Majumder

Reputation: 41200

? means wild card it a generic symbol. It means HttpEntity of unknown.

Upvotes: 1

Related Questions