Bird
0
0

What is wrong with this method to return 204 No Content?

medium📝 Debug Q7 of 15
Spring Boot - Request and Response Handling
What is wrong with this method to return 204 No Content?
@DeleteMapping("/delete")
public ResponseEntity delete() {
  return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
AVoid type cannot be used with ResponseEntity
BResponseEntity constructor requires two parameters
CThis method correctly returns 204 No Content
DMust include a response body with 204 status
Step-by-Step Solution
Solution:
  1. Step 1: Understand ResponseEntity with Void type

    ResponseEntity is valid to indicate no body in the response.
  2. Step 2: Check constructor usage

    Using new ResponseEntity<>(HttpStatus.NO_CONTENT) correctly sets status 204 with no body.
  3. Final Answer:

    This method correctly returns 204 No Content -> Option C
  4. Quick Check:

    ResponseEntity with status only is valid [OK]
Quick Trick: Use ResponseEntity for no content responses [OK]
Common Mistakes:
  • Thinking Void is invalid in ResponseEntity
  • Assuming 204 requires a body
  • Expecting two parameters in constructor always

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Spring Boot Quizzes