### Question:
LastOfChannelExpression implements DesiredRateExpression<T> { public <N> LastOfChannelExpression<N> cast(Class<N> clazz) { if (clazz.isAssignableFrom(this.clazz)) { @SuppressWarnings("unchecked") LastOfChannelExpression<N> result = (LastOfChannelExpression<N>) this; return result; } if (this.clazz.isAssignableFrom(clazz)) { return new LastOfChannelExpression<N>(getName(), clazz); } throw new IllegalArgumentException("Cannot cast expression of type " + this.clazz + " to type " + clazz); } LastOfChannelExpression(String name, Class<T> clazz); @Override DesiredRateExpression<T> as(String name); @Override String getName(); @Override void fillReadRecipe(PVDirector director, ReadRecipeBuilder builder); @Override ReadFunction<T> getFunction(); @Override DesiredRateExpressionImpl<T> getDesiredRateExpressionImpl(); @Override DesiredRateExpressionList<T> and(DesiredRateExpressionList<? extends T> expressions); @Override List<DesiredRateExpression<T>> getDesiredRateExpressions(); LastOfChannelExpression<N> cast(Class<N> clazz); Class<T> getType();  }### Answer:
@Test public void testCast1() { LastOfChannelExpression<Object> exp = new LastOfChannelExpression<Object>("test", Object.class); LastOfChannelExpression<Object> exp2 = exp.cast(Object.class); assertThat(exp2, sameInstance(exp)); }
@Test(expected=IllegalArgumentException.class) public void testCast4() { LastOfChannelExpression<VDouble> exp = new LastOfChannelExpression<VDouble>("test", VDouble.class); LastOfChannelExpression<?> exp2 = exp.cast(VString.class); }