Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is hard to tell what you are asking, but according to the <a href="http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#228080" rel="nofollow noreferrer">Java Language Specification</a>:</p> <p><i>In a situation such as this:</i></p> <pre><code>interface Fish { int getNumberOfScales(); } interface StringBass { double getNumberOfScales(); } class Bass implements Fish, StringBass { // This declaration cannot be correct, no matter what type is used. public ??? getNumberOfScales() { return 91; } } </code></pre> <p><i>It is impossible to declare a method named getNumberOfScales with the same signature and return type as those of both the methods declared in interface Fish and in interface StringBass, because a class can have only one method with a given signature (§8.4). Therefore, it is impossible for a single class to implement both interface Fish and interface StringBass.</i></p> <p>However, if both of your interfaces specify the same return type, then you can go ahead and implement that method. If <code>MyUser</code> and <code>YourUser</code> have a common ancestor then you could do <code>List&lt;? extends User&gt;</code> or if they have no commonality you can use simply use <code>List&lt;?&gt;.</code></p> <p>At that point though, you have to stop and consider if a common implementation is what you actually want. I suspect there may be a more elegant solution, if you provided us with more details about your problem.</p> <p><b>Edit:</b></p> <p>Based on your comment, you want something like...</p> <pre><code>interface MyUserGetter { List&lt;? extends MyUser&gt; getUsers(); } interface YourUserGetter { List&lt;? extends YourUser&gt; getUsers(); } class UserGetterImpl { List&lt;? extends UserImpl&gt; getUsers(); } </code></pre> <p>This is untested, and I'd guess has a 50% chance of working.</p> <p>The architectural suggestion is that instead of having a single implementation for two interfaces you might actually want two implementations of one interface:</p> <pre><code>interface User {} class MyUser implements User {} class YourUser implements User {} interface UserGetter { List&lt;? extends User&gt; getUsers(); } </code></pre>
    singulars
    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.
 

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