意味をなさない Hadoop フレームワークの製品コードを見ています。なぜ一時的なものを使用しているのか、またユーティリティ メソッドを静的メソッドにできないのはなぜですか (主任から isThinger を静的メソッドにしないように言われました)。一時的なキーワードを調べたところ、シリアライゼーションに関連しています。シリアル化は本当にここで使用されていますか?
//extending from MapReduceBase is a requirement of hadoop
public static class MyMapper extends MapReduceBase {
// why the use of transient keyword here?
transient Utility utility;
public void configure(JobConf job) {
String test = job.get("key");
// seems silly that we have to create Utility instance.
// can't we use a static method instead?
utility = new Utility();
boolean res = utility.isThinger(test);
foo (res);
}
void foo (boolean a) { }
}
public class Utility {
final String stringToSearchFor = "ineverchange";
// it seems we could make this static. Why can't we?
public boolean isThinger(String word) {
boolean val = false;
if (word.indexOf(stringToSearchFor) > 0) {
val = true;
}
return val;
}
}