class MutableTomlArray implements TomlArray {

  MutableTomlArray append(Object value, TomlPosition position) {
    requireNonNull(value);
    if (value instanceof Integer) {
      value = ((Integer) value).longValue();
    }

    TomlType origType = type;
    Optional<TomlType> valueType = typeFor(value);
    if (!valueType.isPresent()) {
      throw new IllegalArgumentException("Unsupported type " + value.getClass().getSimpleName());
    }
    if (type != null) {
      if (valueType.get() != type) {
        throw new TomlInvalidTypeException(
            "Cannot add a " + typeNameFor(value) + " to an array containing " + type.typeName() + "s");
      }
    } else {
      type = valueType.get();
    }

    try {
      elements.add(new Element(value, position));
    } catch (Throwable e) {
      type = origType;
      throw e;
    }
    return this;
  }

    MutableTomlArray();
    MutableTomlArray(boolean definedAsLiteral);

}