任何人都可以帮我找到下面代码中的错误吗?

时间:2014-11-27 09:52:45

标签: java

我没有从传递引用的方法获取更新列表

    List<Person> beans = new ArrayList<Person>();
    boolean alreadyPresent = isPersonPresentOnSolr(solrServer, beans);

    // beans.size() is zero
    boolean isPersonPresentOnSolr(SolrServer solrServer, List<Person> beans)
   {
    QueryResponse response   = solrServer.query(solrQry);                
    beans = response.getBeans(Person.class);

    //beans.size()  is 5
   }

1 个答案:

答案 0 :(得分:1)

你不应该做

beans = response.getBeans(Person.class); // you lost reference of object. it is c++ way,
//but not works for java

你应该做

List<Person> newBeans = response.getBeans(Person.class);
beans.addAll(newBeans);