class
フィールドにはpublic static final
フィールドがある場合は、 、次にspring Contants
クラスは、これらのフィールドにヘルプを提供するのに役立ちます。大文字小文字の区別はありません
しかし、lower case field name,
Contants
は扱いにくいです。 Java
仕様の提案 upper case
public static final
のフィールド名は ですが、lower case
の名前はまだ有効です。
は、例を参照してください。
public class Test {
public static final int a = 1;
public static final int B = 2;
public static void main(String[] args) {
org.springframework.core.Constants constants = new org.springframework.core.Constants(Test.class);
System.out.println(constants.asNumber("b").intValue()); // line 1
System.out.println(constants.asNumber("a").intValue()); // line 2
}
}
line 1
意志出力2
、 しかしline 2
はthrow ConstantException: Field 'A' not found in class Test
は、なぜ彼らは大文字と小文字が区別、それらを比較しないのだろうか?そのため大会の
しかし、私はまだConstantをStringユーザーの入力と比較して、大文字に変更する必要はないと考えています。 1行目例外をスローするフィールド 'b'がクラスTestに見つかりません – andy