小ネタです。
Javaのenumって色々できて色々やばいのですが、こんな風にかけるのかなーっと恐る恐るEclipseに打ち込んで見たら何の問題も無くできました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum Test { | |
One, | |
Two{ | |
@Override | |
public String toString(){ | |
return "One"; | |
} | |
}, | |
} | |
public class EnumTest { | |
public static void main(String[] args){ | |
System.out.println(Test.One); | |
System.out.println(Test.Two); | |
// One | |
// One | |
} | |
} |
なんでこんな事やった!
ちょっと一部の要素だけ別の文字列を返して欲しい場面があったもので・・・
乱用するなよ!
はい・・・
0 件のコメント:
コメントを投稿