我在访问代码中的某些字段时遇到问题,我想知道一种处理此问题的有效方法。
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);
}
答案 0 :(得分: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