Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Generic class implementing non-generic interface

800357Feb 1 2009 — edited Feb 5 2009
Hello,

I'm having problems implementing a non-generic interface that however contains a generic method:
public interface GeneticOperator {
	public <I extends Individual<G>, G> Population<I, G> apply( Population<I, G> pop );
	...
}
I want to use a generic class to implement this, but I can't find the proper way to implement the method from the interface. This seemed to me the way to do it:
public abstract class AbstractMutator<I extends Individual<G>, G> implements GeneticOperator {
	public Population<I, G> apply( Population<I, G> pop ) { ... }
	...
}
Eclipse compiler says: Name clash: The method apply(Population<I,G>) of type AbstractMutator<I,G> has the same erasure as apply(Population<I,G>) of type GeneticOperator but does not override it

I think I sort of half understand why this happens, although this seems a legal way of implementing the method to me. The reason why GeneticOperator isn't generic is that it doesn't make sense for all implementing classes to be generic. It does make sense though for Mutators, so I want to make that a generic class. Any way this can be done?

Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 5 2009
Added on Feb 1 2009
19 comments
685 views