0

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?

2
  • I have two separate types that need to go in there and they both extend different base classes. The second wildcard is incomplete as I couldn't figure out the syntax to express what I needed. Commented May 25, 2012 at 18:34
  • Oh nevermind, I just re-read your code and posted an answer. Commented May 25, 2012 at 22:03

3 Answers 3

2

Try declaring your method this way:

public <T extends SDOBase, E extends BaseEntity> T entityToSDO(E entity, T sdo) throws Exception;
Sign up to request clarification or add additional context in comments.

Comments

0

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;
}

1 Comment

<? extends BaseEntity> entity isn't valid syntax for a method parameter.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.