• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

Generic problem

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to genercise my Entity interface :

So the getVersion method returns a typed Comparable.

I'm trying this :



The idea being that the getVersion method returns a Comparable object that is comparable with itself.

with concrete implementation :



I get an error saying I'm not implementing the getVersion method. Ack!
Anyone know how to solve this?

thanks, D.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"I get an error saying I'm not implementing the getVersion method. Ack!"

Are you sure? I tried compiling your code and did not get an error, just a warning:

C:\Jesper\workspace\Sandbox\src>javac -Xlint:unchecked org\jesperdj\sandbox\*.java
org\jesperdj\sandbox\Employee.java:5: warning: getVersion() in org.jesperdj.sandbox.Employee implements <T>getVersion() in org.jesperdj.sandbox.Entity; return type requires unchecked conversion
found : java.lang.Long
required: java.lang.Comparable<T>
public Long getVersion() {
^
1 warning
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If the return type if fixed for each implementation of the interface, you should add the type parameter to the interface:



Also note that the above type parameter is the correct declaration of a "type that is comparable to itself". Your declaration was just a "type that is comparable to a (potentially different) comparable type", as far as I can tell.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic