2013-06-18 88 views
0

我在访问我的代码中的某些字段时遇到问题,我想知道处理此问题的有效方法。访问字段,Java

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

什么是某些领域? – Sam

+0

@你是什么意思“无法访问startKeyIndex的值”。它给你编译错误? –

回答

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