0

以下のコードでは、私の期待は、listがメソッド内にあるreaderList.size = 0べきheaderLineであるということです。しかし、そうではありません、誰かが理由を教えてもらえますか?nullcommonValidation()

String[] headerLine = null;

if (readerList != null && readerList.size() != 0){
    headerLine = readerList.get(0);         
}

commonValidation(headerLine, logDTO, hrGroupName, feedFileName);

//メソッド定義

public void commonValidation(String[] headerLine, TransactionLogDTO logDTO, String hrGroupName, String filename) throws PersistenceException, ServiceException, Exception {
    if ((headerLine == null) || (headerLine.length == 0)){
        logDTO.setGyr("R");

            String subject = MessageWrapper.getMessage("hr.mail.emptyfile.subject");
        String body = MessageWrapper.getMessage("hr.mail.emptyfile.body", filename);

            if (logDTO.getMessage() == null){
                logDTO.setMessage(body);
            }
            else{
                logDTO.setMessage(logDTO.getMessage() + ";" + body);
            }

        logDTO.setIsLogErrorMailSent(Boolean.TRUE);

        sendTransactionLogErrorReport(hrGroupName, subject, body);                  

        throw new Exception(body);
    }
}
4

2 に答える 2

2

String[] headerLine = null;これはメンバー変数ですか?はいの場合は、メソッドをローカル変数にします。

また

ArrayListにnull要素を追加すると、サイズが大きくなります。

    ArrayList<String[]> arrayList = new ArrayList<String[]>();
    arrayList.add(null);
    System.out.println(arrayList.size());

印刷し1ません0

だからチェックするかreaderList.get(0)どうnull

ArrayList addメソッドのソースコードは次のとおりです

 410       public boolean add(E e) {
 411           ensureCapacityInternal(size + 1);  // Increments modCount!!
 412           elementData[size++] = e;
 413           return true;
 414       }

チェックがない場合はnull、自分で行う必要があります:)

于 2012-09-04T09:25:35.567 に答える
0

しかし、そうではありません、(...)

私は信じません。readerList.size() == 0 headerLineが値を変更せず、そのままの場合null

于 2012-09-04T09:40:34.000 に答える