code: public int write(OutputStream dest, int id, Object obj) throws IOException {
          int idx;
  
          if (obj == null) {
              throw new NullPointerException("write null");
          }
          idx = addIfNew(id, obj);
          IO.writeU2(dest, idx);
          return idx;
      }
docs: the id and and int id is easier to handle than a reference.