MikeG
MikeG

Reputation: 1275

Creating two generic parameters in an interface

I am trying to create a generic interface for my classes that will satisfy them all. I have created base classes to link them all together but the interface I'm trying to create isn't working like I'd expect it to and I cant find the right words to type into the search to find them.

The interface so far is:

public <T extends SDOBase> T entityToSDO(<? extends BaseEntity> entity, T sdo) throws Exception;

How do I make entity a second generic type?

Upvotes: 0

Views: 89

Answers (3)

newacct
newacct

Reputation: 122439

You just need

public <T extends SDOBase> T entityToSDO(BaseEntity entity, T sdo) throws Exception;

Anything that is an instance of a subtype of BaseEntity automatically is an instance of BaseEntity.

Upvotes: 0

Jeshurun
Jeshurun

Reputation: 23186

Try declaring your method this way:

public <T extends SDOBase, E extends BaseEntity> T entityToSDO(E entity, T sdo) throws Exception;

Upvotes: 2

dnc253
dnc253

Reputation: 40337

I think you want something more along the lines of:

public interface MyInterface<T extends SDOBase>
{
    public T entityToSDO(<? extends BaseEntity> entity, T sdo) throws Exception;
}

Upvotes: 0

Related Questions