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 TypeMarker static factory method #2263

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,24 @@ protected TypeMarker() {
genericSuperclass instanceof ParameterizedType,
"Class is not parameterized",
SafeArg.of("class", genericSuperclass));
type = ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0];
Type typeArgument = ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0];
Preconditions.checkArgument(
!(typeArgument instanceof TypeVariable),
"TypeMarker does not support variable types",
SafeArg.of("typeVariable", typeArgument));
this.type = typeArgument;
}

private TypeMarker(Type type) {
Preconditions.checkArgument(
!(type instanceof TypeVariable),
"TypeMarker does not support variable types",
SafeArg.of("typeVariable", type));
this.type = type;
}

public static <T> TypeMarker<T> of(Type type) {
return new TypeMarker<>(type) {};
Comment on lines +61 to +62
Copy link
Member Author

Choose a reason for hiding this comment

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

Is there something we can do to make this more type safe? I don't think so since we're operating with runtime time values at this point.

}

public final Type getType() {
Expand Down