New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add external content fetcher #392
Conversation
|
||
@Override | ||
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
return type == ContentInputStream.class; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably want to use "instanceof" instead of "==".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, don't. (type instanceof ContentInputStream) is always false, because (type instanceof Class<?>) is always true. And thanks to type erasure, (type instanceof Class) is not useful. == is the best you can do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could at least account for subtyping, using Class.isAssignableFrom() and ParameterizedType.getActualTypeArguments().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like the way to go:
ContentInputStream.class.isAssignableFrom(type)
Is ParameterizedType.getActualTypeArguments() necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. I was making the general point that if the type in question here was generic, which it is not, ParameterizedType.getActualTypeArguments() would be the way to deal with that.
} | ||
} | ||
|
||
@VisibleForTesting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice touch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, learned that one a couple weeks ago. Seems better than reflection, at least.
Resolved with: 1fcf260 Addresses: https://www.pivotaltracker.com/story/show/72099626 |
https://www.pivotaltracker.com/story/show/72099626