Dan Brandt
Dan Brandt

Reputation: 615

ResponseEntity<?> and ResponseEntity are not the same?

I know that raw types are bad in code, and List<?> and List, for example, are different things. But what about situation with ResponseEntity<?> and ResponseEntity? Using in @RestController.

Upvotes: 7

Views: 16082

Answers (3)

klabe
klabe

Reputation: 495

ResponseEntity<?> is read-only. You can not write to it. However, the raw type ResponseEntity is writeable.

Upvotes: 3

20 fps
20 fps

Reputation: 342

ResponseEntity<?> it's kinda trick for IDE, so it's not gonna say you have raw type in your code.

So they are actually absolutely the same, anyway I'd suggest you do not use raw type and provide generic types for any of you response entities.

Upvotes: 3

Afaq Ahmed Khan
Afaq Ahmed Khan

Reputation: 2302

They are actually the same, compiler would replace it with generic type, if you see here in the documentation ResponseEntity it's actually

class ResponseEntity<T>

so ResponseEntity<?> and ResponseEntity are the same.

Upvotes: 13

Related Questions