Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In what voodoo have you got yourself into :) ? <strong>From the question and comments I assumed that you are sure that you have objects that extend abstract class <code>SomeClass</code> and also implement interface <code>SomeOtherClass</code>.</strong> If this is the case I suggest an intermediate abstract class in the hierarchy that share these properties.</p> <pre><code>public abstract class Foo&lt;K&gt; extends SomeClass implements SomeOtherClass&lt;K&gt; { ... } </code></pre> <p>That way you could simplify the static method signature to:</p> <pre><code>public &lt;K,V extends Foo&lt;K&gt;&gt; void doSomethingWithSomeMap (Map&lt;K,V&gt; map, V data); </code></pre> <p>If you do not want to change your current object hierarchy you can fool the compiler using another level of indirection with the <a href="http://en.wikipedia.org/wiki/Adapter_pattern" rel="nofollow noreferrer">adapter pattern</a>.</p> <blockquote> <p>"All problems in computer science can be solved by another level of indirection." -- David Wheeler</p> </blockquote> <pre><code>public abstract class SomeClass { public abstract void method1(); } public interface SomeOtherClass&lt;K&gt; { void method2(K value); } public class MyClass extends SomeClass implements SomeOtherClass&lt;Integer&gt; { @Override public void method1() { System.out.println("MyClass.method1"); } @Override public void method2(Integer value) { System.out.println("MyClass.method2(" + value + ")"); } } public class Indirection&lt;K&gt; extends SomeClass implements SomeOtherClass&lt;K&gt; { private final Object objectValue; public Indirection(final Object value) { this.objectValue = value; } @Override public void method1() { ((SomeClass) objectValue).method1(); } @Override public void method2(K value) { @SuppressWarnings("unchecked") SomeOtherClass&lt;K&gt; delegate = ((SomeOtherClass&lt;K&gt;) objectValue); delegate.method2(value); } } public static void main(String[] args) { Map someMap = new HashMap&lt;Integer, MyClass&gt;(); SomeClass someData = new MyClass(); Indirection a = new Indirection(someData); doSomethingWithSomeMap(someMap, a, 12); } public static &lt;K,V extends SomeClass &amp; SomeOtherClass&lt;K&gt;&gt; void doSomethingWithSomeMap (Map&lt;K,V&gt; map, V data, K value) { data.method1(); data.method2(value); } </code></pre> <p>This would print:</p> <blockquote> <p>MyClass.method1<br/> MyClass.method2(12)</p> </blockquote>
    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.
 

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