aspose file tools*
The moose likes Java in General and the fly likes Generic problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generic problem" Watch "Generic problem" New topic
Author

Generic problem

Don Kiddick
Ranch Hand

Joined: Dec 12, 2002
Posts: 580
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14338
    
  22

"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


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
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.


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generic problem