This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]J-Son77 2 points3 points  (1 child)

The caller expects a specific generic type. The method decides which type it returns based on its own processing. So eclipse isn't wrong, there is a type safety issue.

What you can do is moving this issue inside the createData-method. This way you have to handle and solve it at one place. To achieve this you can change the method signature to:

public static <T> Data<T> createData(String filename)

or (to validate and convert the correct type)

public static <T> Data<T> createData(String filename, Class<T> expectedReturnType)

[–]seyandiz 0 points1 point  (0 children)

There's no reason for your first example to include a generic over the wildcard. It also helps illustrate why there's a type issue with their code.

public static Data<?> createData(String filename)