我正在努力掌握Google App Engine编程,并想知道这两种方法之间的区别是什么 - 如果有实际差异的话.
方法A)
public Collection<Conference> getConferencesToAttend(Profile profile)
{
List<String> keyStringsToAttend = profile.getConferenceKeysToAttend();
List<Conference> conferences = new ArrayList<Conference>();
for(String conferenceString : keyStringsToAttend)
{
conferences.add(ofy().load().key(Key.create(Conference.class,conferenceString)).now());
}
return conferences;
}
Run Code Online (Sandbox Code Playgroud)
方法B)
public Collection<Conference> getConferencesToAttend(Profile profile)
List<String> keyStringsToAttend = profile.getConferenceKeysToAttend();
List<Key<Conference>> keysToAttend = new ArrayList<>();
for (String keyString : keyStringsToAttend) {
keysToAttend.add(Key.<Conference>create(keyString));
}
return ofy().load().keys(keysToAttend).values();
}
Run Code Online (Sandbox Code Playgroud)
"conferenceKeysToAttend"列表保证只有唯一的会议 - 即使我选择了两种备选方案中的哪一种呢?如果是这样,为什么?