Created
March 25, 2016 11:22
-
-
Save kawasima/402c4ae011de4563dbeb to your computer and use it in GitHub Desktop.
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
public interface CodeEnum { | |
String getLabel(); | |
String getCode(); | |
} |
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
public enum Gender implements CodeEnum { | |
FEMALE("F", "女"), | |
MALE("M", "男"), | |
OTHER("O", "その他"); | |
private String label; | |
private String code; | |
Gender(String code, String label) { | |
this.label = label; | |
this.code = code; | |
} | |
@Override | |
public String getLabel() { | |
return label; | |
} | |
@Override | |
public String getCode() { | |
return code; | |
} | |
} |
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
Arrays.stream(Gender.values()) | |
.map(g -> "<option value=\"" + g.getCode() | |
+ "\">" + g.getLabel() | |
+ "</option>") | |
.forEach(System.out::println); | |
<option value="F">女</option> | |
<option value="M">男</option> | |
<option value="O">その他</option> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment