title: Create and add object to RealmList in RealmMigration
body: <p>In my current app, I have a <code>HolderObject</code> (which extends <code>RealmObject</code>) with a <code>long</code> 'machineId'. In a new version of the app, this <code>HolderObject</code> will be able to contain more machines, in the form of a RealmList. See the classes below:</p>
  
  <p>Old object:</p>
  
  <pre><code>public class HolderObject extends RealmObject{
      private long machineId;
      //.. getters and setters
  }
  </code></pre>
  
  <p>New object:</p>
  
  <pre><code>public class HolderObject extends RealmObject{
      private RealmList&lt;RealmLong&gt; machineIds;
      //.. getters and setters
  }
  </code></pre>
  
  <p>In which <code>RealmLong</code> is as follows:</p>
  
  <pre><code>public class RealmLong extends RealmObject {
      private long val;
      //.. getters and setters
  }
  </code></pre>
  
  <p>To migrate all old <code>HolderObject</code>s to the new objects, I use my custom RealmMigration. This is as follows:</p>
  
  <pre><code>public class CustomRealmMigration implements RealmMigration {
      @Override
      public void migrate(DynamicRealm realm, long oldVersion, long newVersion) {
          RealmSchema schema = realm.getSchema();
  
          schema.get("HolderObject")
                  .addRealmListField("machineIds", schema.get("RealmLong"))
                  .transform(new RealmObjectSchema.Function() {
                      @Override
                      public void apply(DynamicRealmObject obj) {
                          Realm realm = Realm.getDefaultInstance();
                          realm.beginTransaction();
                          RealmLong realmLong = realm.createObject(RealmLong.class);
                          realmLong.setVal(obj.getLong("machineId"));
                          obj.getList("machineIds").add(realmLong);
                          realm.commitTransaction();
                          realm.close();
                      }
                  });
      }
  }
  </code></pre>
  
  <p><strong>Question:</strong></p>
  
  <ul>
  <li>In the line <code>obj.getList("machineIds").add(realmLong);</code>, I get the error that this function expects a <code>DynamicRealmObject</code>, not a <code>RealmLong</code>. How can I add a <code>RealmLong</code> to this list?</li>
  <li><em>(Bonus question)</em> Is this the correct and best approach to this migration problem?</li>
  </ul>