code: public static <Type extends Message>
    RpcCallback<Message> generalizeCallback(
        final RpcCallback<Type> originalCallback,
        final Class<Type> originalClass,
        final Type defaultInstance) {
      return new RpcCallback<Message>() {
        public void run(final Message parameter) {
          Type typedParameter;
          try {
            typedParameter = originalClass.cast(parameter);
          } catch (ClassCastException ignored) {
            typedParameter = copyAsType(defaultInstance, parameter);
          }
          originalCallback.run(typedParameter);
        }
      };
    }
docs: Take an {@code RpcCallback} accepting a specific message type and convert
  it to an {@code RpcCallback<Message>}.  The generalized callback will
  accept any message object which has the same descriptor, and will convert
  it to the correct class before calling the original callback.  However,
  if the generalized callback is given a message with a different descriptor,
  an exception will be thrown.