Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Add external content fetcher #392

wants to merge 1 commit into from

Conversation

cbeer
Copy link
Contributor

@cbeer cbeer commented May 27, 2014


@Override
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) {
return type == ContentInputStream.class;
Copy link

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 "==".

Copy link
Contributor

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.

Copy link
Contributor

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().

Copy link

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?

Copy link
Contributor

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch

Copy link
Contributor Author

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.

@awoods
Copy link

awoods commented May 28, 2014

Resolved with: 1fcf260

Addresses: https://www.pivotaltracker.com/story/show/72099626

@awoods awoods closed this May 28, 2014
@awoods awoods deleted the external-content branch May 28, 2014 01:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants