/** * Returns this method as a BoundMethod for the given receiver. * * @param target an Object on which to get or set this field * @return a {@link BoundField} for this field and the target * @throws IllegalStateException if the method is static * @throws IllegalArgumentException if the receiver's class is incompatible */ public BoundField<T> bind(Object target) { Preconditions.checkState(!isStatic() || this == AlwaysNull.INSTANCE, "Cannot bind static field " + name); Preconditions.checkArgument( field.getDeclaringClass().isAssignableFrom(target.getClass()), "Cannot bind field " + name + " to instance of " + target.getClass()); return new BoundField<>(this, target); }
/** * Returns this field as a StaticField. * * @return a {@link StaticField} for this field * @throws IllegalStateException if the method is not static */ public StaticField<T> asStatic() { Preconditions.checkState(isStatic(), "Field " + name + " is not static"); return new StaticField<>(this); }