Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want full type safety, I don't think you can do better without some kind of wrapper classes. But, why not make those classes inherit/implement the original generic versions, like this:</p> <pre><code>public class FooBBQ extends Foo&lt;Bar&lt;Baz,Qux&gt;&gt; { ... } </code></pre> <p>This eliminates the need for <code>toGeneric()</code> method, and it is more clear, in my opinion, that it is just a type alias. Also, generic type can be cast into <code>FooBBQ</code> without a compiler warning. It would be my personal preference to make <code>Foo, Bar, Baz...</code> interfaces, if possible, even if some code duplication would occur in implementation.</p> <p>Now, without knowing concrete problem domain, it is hard to say whether you need, say <code>FooBBQ</code>, like in your example, or perhaps a:</p> <pre><code>public class FooBar&lt;X, Y&gt; extends Foo&lt;Bar&lt;X, Y&gt;&gt; { ... } </code></pre> <p>On the other hand, have you thought about simply configuring Java compiler not to show some of the generic warnings, and simply omit the parts of generic definition? Or, use strategically placed <code>@SuppressWarnings("unchecked")</code>? In other words, can you make <code>DoableImpl</code> only "partly genericized":</p> <pre><code>class DoableImpl implements Doable&lt;Foo&lt;Bar&gt;&gt;,Foo&lt;Bar&gt;&gt; { Foo&lt;Bar&gt; doIt(Foo&lt;Bar&gt; foobar) { ... } } </code></pre> <p>and ignore the warnings for the sake of less code clutter? Again, hard to decide without a concrete example, but it is yet another thing you can try. </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. 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