Forum Stats

  • 3,727,530 Users
  • 2,245,404 Discussions
  • 7,852,847 Comments

Discussions

Used to compile in java 7, not so much in java 8.

user10050369
user10050369 Member Posts: 2
edited June 2015 in Java 8 Questions

<span class="kwd" style="color: #00008b;">The fails() method used to compile properly, but it doesn't anymore. The now() method seems to lose track of its return type and now forces me to cast (which I didn't have to do in java 7).  The problem seems to arise only if I use the new SelfLink(); using similarly typed interfaces works fine.</span>


I may be doing something wrong, but for the life of me, I can't figure it out.


<span class="kwd" style="color: #00008b;">Here is the code.</span>


<span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">class</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">Main</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="com" style="color: #808080;">// The command</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">interface</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">ToMessageOperation</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">void</span><span class="pln" style="color: #000000;"> run</span><span class="pun" style="color: #000000;">(</span><span class="pln" style="color: #000000;">MODEL object</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> MESSAGE message</span><span class="pun" style="color: #000000;">)</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">throws</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">Exception</span><span class="pun" style="color: #000000;">;</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="com" style="color: #808080;">// A command</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">class</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">SelfLink</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">implements</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">ToMessageOperation</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="lit" style="color: #800000;">@Override</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">void</span><span class="pln" style="color: #000000;"> run</span><span class="pun" style="color: #000000;">(</span><span class="pln" style="color: #000000;">MODEL object</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pln" style="color: #000000;"> linkedMessage</span><span class="pun" style="color: #000000;">)</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">throws</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">Exception</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="com" style="color: #808080;">// A message type</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">interface</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">void</span><span class="pln" style="color: #000000;"> linkme</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="com" style="color: #808080;">// A message</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">interface</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">extends</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="com" style="color: #808080;">//The Executor</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">interface</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">GetRequest</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="typ" style="color: #2b91af;">GetRequest</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> runAll</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">ToMessageOperation</span><span class="pun" style="color: #000000;"><?</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">super</span><span class="pln" style="color: #000000;"> MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">?</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">super</span><span class="pln" style="color: #000000;"> MESSAGE</span><span class="pun" style="color: #000000;">>...</span><span class="pln" style="color: #000000;"> operations</span><span class="pun" style="color: #000000;">);</span><span class="pln" style="color: #000000;"><br/>   </span><span class="typ" style="color: #2b91af;">GetRequest</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> cleanUp</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>  MESSAGE now</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="com" style="color: #808080;">// The command factory</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">SelfLink</span><span class="pln" style="color: #000000;"> selfLink</span><span class="pun" style="color: #000000;">()</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">return</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">null</span><span class="pun" style="color: #000000;">;</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">GetRequest</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;">MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> get</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">Class</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> message</span><span class="pun" style="color: #000000;">)</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">return</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">null</span><span class="pun" style="color: #000000;">;</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pln" style="color: #000000;"> works</span><span class="pun" style="color: #000000;">()</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">return</span><span class="pln" style="color: #000000;"> get</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pun" style="color: #000000;">.</span><span class="kwd" style="color: #00008b;">class</span><span class="pun" style="color: #000000;">).</span><span class="pln" style="color: #000000;">cleanUp</span><span class="pun" style="color: #000000;">().</span><span class="pln" style="color: #000000;">now</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pln" style="color: #000000;"> alsoWorks</span><span class="pun" style="color: #000000;">()</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">return</span><span class="pln" style="color: #000000;"> get</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pun" style="color: #000000;">.</span><span class="kwd" style="color: #00008b;">class</span><span class="pun" style="color: #000000;">).</span><span class="pln" style="color: #000000;">runAll</span><span class="pun" style="color: #000000;">(</span><span class="kwd" style="color: #00008b;">new</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">ToMessageOperation</span><span class="pun" style="color: #000000;"><</span><span class="typ" style="color: #2b91af;">Object</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pun" style="color: #000000;">>()</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/>   </span><span class="lit" style="color: #800000;">@Override</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">void</span><span class="pln" style="color: #000000;"> run</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">Object</span><span class="pln" style="color: #000000;"> object</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pln" style="color: #000000;"> bootInfo</span><span class="pun" style="color: #000000;">)</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">throws</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">Exception</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;">  <br/>   </span><span class="pun" style="color: #000000;">}).</span><span class="pln" style="color: #000000;">now</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pln" style="color: #000000;"> surprisedItWorks</span><span class="pun" style="color: #000000;">()</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">return</span><span class="pln" style="color: #000000;"> get</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pun" style="color: #000000;">.</span><span class="kwd" style="color: #00008b;">class</span><span class="pun" style="color: #000000;">).</span><span class="pln" style="color: #000000;">runAll</span><span class="pun" style="color: #000000;">(</span><span class="kwd" style="color: #00008b;">new</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">ToMessageOperation</span><span class="pun" style="color: #000000;"><</span><span class="typ" style="color: #2b91af;">Object</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pun" style="color: #000000;">>()</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/>   </span><span class="lit" style="color: #800000;">@Override</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">void</span><span class="pln" style="color: #000000;"> run</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">Object</span><span class="pln" style="color: #000000;"> object</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pln" style="color: #000000;"> message</span><span class="pun" style="color: #000000;">)</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">throws</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">Exception</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;">  <br/>   </span><span class="pun" style="color: #000000;">}).</span><span class="pln" style="color: #000000;">now</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pln" style="color: #000000;"> fails</span><span class="pun" style="color: #000000;">()</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">return</span><span class="pln" style="color: #000000;"> get</span><span class="pun" style="color: #000000;">(</span><span class="typ" style="color: #2b91af;">BootInfo</span><span class="pun" style="color: #000000;">.</span><span class="kwd" style="color: #00008b;">class</span><span class="pun" style="color: #000000;">).</span><span class="pln" style="color: #000000;">runAll</span><span class="pun" style="color: #000000;">(</span><span class="kwd" style="color: #00008b;">new</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">SelfLink</span><span class="pun" style="color: #000000;">()).</span><span class="pln" style="color: #000000;">now</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/><br/></span><span class="pun" style="color: #000000;">}</span>

Answers

  • Unknown
    edited June 2015
    <span class="kwd" style="color: #00008b;">The fails() method used to compile properly, but it doesn't anymore. The now() method seems to lose track of its return type and now forces me to cast (which I didn't have to do in java 7).  The problem seems to arise only if I use the new SelfLink(); using similarly typed interfaces works fine.</span>
    
    

    I don't know how that could have compiled in Java 7. Your 'SelfLink' declares that it implements 'ToMessageOperation' but that interface requires a 'MODEL' and a 'MESSAGE'. Your class declares using 'MODEL' and 'LinkedMessage' and the latter does NOT extend 'MESSAGE'.

    <span class="pln" style="color: #000000;">   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">interface</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">ToMessageOperation</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> MESSAGE</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/></span><span class="pln" style="color: #000000;">   </span><span class="com" style="color: #808080;">// A command</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">class</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">SelfLink</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">implements</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">ToMessageOperation</span><span class="pun" style="color: #000000;"><</span><span class="pln" style="color: #000000;">MODEL</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pun" style="color: #000000;">></span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="lit" style="color: #800000;">@Override</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">void</span><span class="pln" style="color: #000000;"> run</span><span class="pun" style="color: #000000;">(</span><span class="pln" style="color: #000000;">MODEL object</span><span class="pun" style="color: #000000;">,</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pln" style="color: #000000;"> linkedMessage</span><span class="pun" style="color: #000000;">)</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">throws</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">Exception</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/></span><span class="pln" style="color: #000000;">   </span><span class="com" style="color: #808080;">// A message type</span><span class="pln" style="color: #000000;"><br/>   </span><span class="kwd" style="color: #00008b;">public</span><span class="pln" style="color: #000000;"> </span><span class="kwd" style="color: #00008b;">interface</span><span class="pln" style="color: #000000;"> </span><span class="typ" style="color: #2b91af;">LinkedMessage</span><span class="pln" style="color: #000000;"> </span><span class="pun" style="color: #000000;">{</span><span class="pln" style="color: #000000;"><br/><br/>   </span><span class="kwd" style="color: #00008b;">void</span><span class="pln" style="color: #000000;"> linkme</span><span class="pun" style="color: #000000;">();</span><span class="pln" style="color: #000000;"><br/>   </span><span class="pun" style="color: #000000;">}</span><span class="pln" style="color: #000000;"><br/></span>

    <span class="pln" style="color: #000000;">If you implement 'ToMessageOperation' using generics those generics have to be compatible with the generics defined in the interface declaration.</span>

    <span class="pln" style="color: #000000;"></span>

    <span class="pln" style="color: #000000;">What is it you are trying to do?</span>

    <span class="pln" style="color: #000000;"> </span>

  • user10050369
    user10050369 Member Posts: 2
    edited June 2015

    SelfLink<MODEL> actually implements ToMessageOperation<MODEL, LinkedMessage>, so both parameters are filled. The command runner (GetRequest.runAll) should accept commands that can run on any super class of the model and the message.  The compiler should be able to figure this out ,and I'm pretty sure it did in java7.

    I'm not sure about what you are saying, as this is a valid statement:

    public class ListOfStrings extends ArrayList<String> {

    }

    public void fun() {

      List<String> s = new ListOfStrings();
       list(new ListOfStrings());
    }

    public void list(List<? super String> fun) {

    }

    That said, and this is the important part, you put your finger on the error and a simple fix.  Thank you very much.

    // A command
    public class SelfLink<MODEL,MESSAGE extends LinkedMessage> implements ToMessageOperation<MODEL, MESSAGE> {

       @Override
       public void run(MODEL object, MESSAGE linkedMessage) throws Exception {

       }

    }

    public <MODEL,MESSAGE extends LinkedMessage> SelfLink<MODEL, MESSAGE> selfLink() {

       return null;
    }

  • Unknown
    edited June 2015
    SelfLink<MODEL> actually implements ToMessageOperation<MODEL, LinkedMessage>, so both parameters are filled.
    

    Yes - but you did NOT post any such 'ToMessageOperation' interface. This is what you posted:

    public interface ToMessageOperation<MODEL, MESSAGE> {
       // A command
       public class SelfLink<MODEL> implements ToMessageOperation<MODEL, LinkedMessage> {

    You posted '<MODEL, MESSAGE>' but you implement 'MODEL, 'LinkedMessage>" and your definition of 'LinkedMessage' does NOT extend 'MESSAGE'.

    That is what I was saying.

    Anyway please mark the thread ANSWERED if you don't need further help.

Sign In or Register to comment.