0
我有下面的代碼的類,傳遞值從一類到另一個調用類
public class DocTransformer implements Callable<IndexableDocument> {
WDoc document;
public DocTransformer(Map<INDEXFIELD, Tokenizer> tknizerMap, WDoc doc) {
this.document = doc;
}
public IndexableDocument call() throws TokenizerException {
System.out.println("Inside doctrans: "+this.document.getId());
}
}
的IndexableDocument類似於下,
public class IndexableDocument {
WDoc doc;
public IndexableDocument() {
System.out.println("this is inside indexable document");
}
public void addField(INDEXFIELD field, TStream stream) {
//TODO: Implement this method
}
public TokenStream getStream(INDEXFIELD key) {
//TODO: Implement this method
return null;
}
public String getDocumentIdentifier() {
System.out.println(doc.getId);
}
}
一個亞軍類調用DocTransformer。我可以在DocTransformer中訪問WDoc,因爲它是從runner類調用的,並且該對象從它傳遞給DocTransformer。但是我需要訪問IndexableDocument中的WDoc對象。如何實現它?請解釋我的問題是否需要改寫,因爲我對線程很陌生。
難道你不能只爲'WDoc doc'字段添加一個getter嗎? –