0

What's wrong with this method definition?

public static List<T extends MyObject> T find() {

}

Compiler says:

Syntax error, insert ";" to complete MethodDeclaration
1
  • Is your class generic ? if not you must delare the method like this: public static <T> List<T extends MyObject> T find() Commented Nov 27, 2014 at 10:43

2 Answers 2

9

You have two return types there.

If you wanted to introduce a generic type T that would be

 public static <T extends MyObject>  List<T> find() {}
Sign up to request clarification or add additional context in comments.

Comments

2

The proper method declaration would be:

public static <T extends MyObject> List<T> find() { ... }

When creating (static) generic methods, the generic parameter(s) has to be defined before the return-type, because they may be used in the return-type.

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.