title: Difference between Mockito.<Response>any().getClass() and Mockito.<Class<Response>>any()?
body: <p>I am trying to understanding how the generics work in case of Mockito.</p>
  <p>I am trying to mock the <code>RestTemplate</code>, however the following code does not compile and I don't know why:</p>
  <pre><code>var expectedResponse = createServiceResponse();
  
  when(restTemplate.exchange(anyString(), any(HttpMethod.class),
          Mockito.&lt;HttpEntity&lt;Object&gt;&gt;any(),
          Mockito.&lt;ServiceResponse&gt;any().getClass(), anyMap()))
          .thenReturn(ResponseEntity.ok(expectedResponse));
  </code></pre>
  <p>The compiler keeps giving me the error message:</p>
  <pre><code>Cannot resolve method 'thenReturn(org.springframework.http.ResponseEntity&lt;T&gt;)
  </code></pre>
  <p>But when I switch <code>Mockito.&lt;ServiceResponse&gt;any().getClass()</code> with <code>Mockito.&lt;Class&lt;ServiceResponse&gt;&gt;any()</code> the compilation succeeds.</p>
  <p>Why is this happening ?</p>
  <p><strong>What is the difference between <code>Mockito.&lt;ServiceResponse&gt;any().getClass()</code> and <code>Mockito.&lt;Class&lt;ServiceResponse&gt;&gt;any()</code> ?</strong></p>
  <p>They should be the same thing right ?</p>
  <p><strong>I mean the class of <code>ServiceResponse</code> should be <code>Class&lt;ServiceResponse&gt;</code>. Right ?</strong></p>
  <p>I don't have a good grasp of advanced generics so I can't understand what the compiler is doing.</p>
  <p>Please do add some description in the answer so that I can understand why this is working the way it is suppose to.</p>