「Java」static final修飾子でクラス定数を利用するサンプル
書式
static final データの型 定数名
使用例
package com.arkgame.study.javlesson;
public class FinalStaticDemo {
public static final String ID_TYPE_B = "2";
public static final String ID_TYPE_C = "3";
public static void main(String[] args) {
// 関数testfuncを呼び出す
System.out.println("value1: " + testfunc(ID_TYPE_B));
System.out.println("value2: " + testfunc(ID_TYPE_C));
}
// 関数testfuncの定義
public static String testfunc(String str) {
if (ID_TYPE_B.equals(str)) {
return "109";
} else if (ID_TYPE_C.equals(str)) {
return "345";
}
return "only return ";
}
}
実行結果
value1: 109
value2: 345