code: public <T extends Type> T resolve(String typeName, Class<T> clazz) {
          Type instance = resolve(typeName);
          if (instance == null) {
              return null;
          }
          if (clazz.isAssignableFrom(instance.getClass())) {
              return clazz.cast(instance);
          } else {
              throw new ParserException("Type error: %s of type %s can not be cast to %s",
                      typeName, instance.getClass(), clazz);
          }
      }
docs: Resolve a type declaration by it's name using this proto context.