More Related Content
Similar to 泥沼の中のパフォーマンスチューニング #JJUG (20)
More from Satoshi Kubo (15)
泥沼の中のパフォーマンスチューニング #JJUG
- 10. Long値
long l = 10000000000; //コンパイルエラー
long l = 10000000000l; //lを付ければOK
- 15. SimpleDateFormat
をベタ書きで
public String format(Date d) {
Calendar cal = Calendar.getInstance();
cal.setTime(d);
StringBuilder build = new StringBuilder();
build.append(cal.get(Calendar.YEAR)).append("/");
int month = cal.get(Calendar.MONTH) + 1;
if(month < 10) {build.append('0');}
build.append(month).append("/");
int dayOfMonth = ......//省略
}
- 22. 呼び出すたびに
リフレクション
public SomeClass execute(String className) throws
ReflectiveOperationException {
Class<SomeInterface> clazz = (Class<SomeInterface>)
Class.forName(className);
SomeInterface i = clazz.newInstance();
return i.execute();
}
- 23. リフレクションを減らす
static final Map<String, Class<SomeInterface>> cache;
static {
cache = new HashMap<>();
// リフレクションでクラスを生成しcacheに入れる
}
public SomeClass execute(String className) throws
ReflectiveOperationException {
return cache.get(className).execute();
}
- 27. キーでリストから探す
static List<SomeClass> list = SomeClass.getList();
SomeClass getById (Integer id) {
for (SomeClass someClass : list) {
if(someClass.getId().equals(id)) {
return someClass;
}
}
return null;
}