title: What's the reason to use ResponseEntity<?> return type instead of simple ResponseEntity in Spring Controller?
body: <p>I've seen a lot of examples of Spring Controllers implementation that use <code>ResponseEntity&lt;?&gt;</code> in order to return HTTP response that have a specific status code and optional body.</p>
  
  <p><code>ResponseEntity&lt;?&gt;</code> notation is present even in official Spring tutorials like the following one: <a href="https://spring.io/guides/tutorials/bookmarks/" rel="noreferrer">Building REST services with Spring</a></p>
  
  <p>What's the reason to use <code>ResponseEntity&lt;?&gt;</code> instead of simple <code>ResponseEntity</code>?</p>
  
  <p>It's a little bit related to my previous question: <a href="https://stackoverflow.com/questions/44974384/sonarqube-complains-about-using-responseentity-with-a-wildcard">SonarQube complains about using ResponseEntity with a wildcard</a></p>
  
  <p>There is some explanation in <a href="https://stackoverflow.com/questions/2770321/what-is-a-raw-type-and-why-shouldnt-we-use-it">What is a raw type and why shouldn't we use it?</a> thread, but I'd like to pay more attention to ResponseEntity class and it's use in Spring Controllers.</p>
  
  <p>Consider the following snippet of code where <code>somethingService</code> returns an <code>Optional</code> of <code>Something</code> class:</p>
  
  <pre><code>@GetMapping
  ResponseEntity&lt;?&gt; getSomething() {
      return somethingService.getSomething()
                 .map(smth -&gt; new ResponseEntity&lt;&gt;(smth, HttpStatus.OK))        
                 .orElse(new ResponseEntity&lt;&gt;(HttpStatus.NOT_FOUND));
  }
  </code></pre>
  
  <p>Is there any reason to leave a wildcard even if I don't get any profit from compiler checks since <code>ResponseEntity(HttpStatus status)</code> parametrises <code>ResponseEntity</code> with <code>Object</code> class?</p>