0

我在访问代码中的某些字段时遇到问题,我想知道一种有效的方法来处理这个问题。

public class Indexer {
static private int startKeyIndex = 0;
    static private String patternKey = new String();
                    .
                    .
private static void extractIndexes(String content) throws IOException {
    patternKey = "this is a regex for finding keywords,  hi!"
    startKeyIndex = extractIndexFromPattern(contentKey, patternKey);
}                   .
                    .
                    .
private static void extractKeywords(String pattern, String content) throws IOException{   
    //The problem is in this method
    CharSequence contentSeq = content.subSequence(0,3000);
    String area = extractStringFromPattern(content, patternKey);    
}
4

1 回答 1

0

一切正常。您也可以访问这些字段和字段值。

import java.io.IOException;

public class Test {
static private int startKeyIndex = 0;


private static void extractIndexes(String content) throws IOException {
    startKeyIndex = 10;
    System.out.println(startKeyIndex);
}                   


private static void extractKeywords(String pattern, String content) throws 
                                                                IOException{   
    System.out.println(startKeyIndex);
}


public static void main(String[] args) throws IOException {
    extractIndexes("");
    extractKeywords("", "");
}


}

结果是:

10
10
于 2013-06-18T09:35:27.257 回答