Created
December 18, 2013 20:22
-
-
Save electrum/8029284 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import static com.google.common.base.Preconditions.checkArgument; | |
import static com.google.common.base.Preconditions.checkNotNull; | |
public final class Types | |
{ | |
private Types() {} | |
public static <A, B extends A> B checkType(A value, Class<B> target, String name) | |
{ | |
checkNotNull(value, "%s is null", name); | |
checkArgument(target.isInstance(value), | |
"%s must be of type %s, not %s", | |
target.getName(), | |
value.getClass().getName()); | |
return target.cast(value); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment