Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First - I have to direct you to <a href="http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html" rel="noreferrer">http://www.angelikalanger.com/GenericsFAQ/JavaGenericsFAQ.html</a> -- she does an amazing job.</p> <p>The basic idea is that you use</p> <pre><code>&lt;T extends SomeClass&gt; </code></pre> <p>when the actual parameter can be <code>SomeClass</code> or any subtype of it.</p> <p>In your example,</p> <pre><code>Map&lt;String, Class&lt;? extends Serializable&gt;&gt; expected = null; Map&lt;String, Class&lt;java.util.Date&gt;&gt; result = null; assertThat(result, is(expected)); </code></pre> <p>You're saying that <code>expected</code> can contain Class objects that represent any class that implements <code>Serializable</code>. Your result map says it can only hold <code>Date</code> class objects.</p> <p>When you pass in result, you're setting <code>T</code> to exactly <code>Map</code> of <code>String</code> to <code>Date</code> class objects, which doesn't match <code>Map</code> of <code>String</code> to anything that's <code>Serializable</code>.</p> <p>One thing to check -- are you sure you want <code>Class&lt;Date&gt;</code> and not <code>Date</code>? A map of <code>String</code> to <code>Class&lt;Date&gt;</code> doesn't sound terribly useful in general (all it can hold is <code>Date.class</code> as values rather than instances of <code>Date</code>)</p> <p>As for genericizing <code>assertThat</code>, the idea is that the method can ensure that a <code>Matcher</code> that fits the result type is passed in.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload