編集の要約なし |
編集の要約なし |
||
| (同じ利用者による、間の5版が非表示) | |||
| 1行目: | 1行目: | ||
< [[Java基本文法]] | |||
* 列挙型 (enum type) とは、フィールドに割り当てられる値(3つ以上)を列挙して限定する仕組み | * 列挙型 (enum type) とは、フィールドに割り当てられる値(3つ以上)を列挙して限定する仕組み | ||
* | * 2つだけなら三項演算子の boolean型の true と false で表現できる | ||
* switch文などで活用できる | |||
# AccountType.java | # AccountType.java | ||
enum AccountType { | enum AccountType { | ||
| 8行目: | 11行目: | ||
public class Account { | public class Account { | ||
private String number; | private String number; | ||
private AccountType type; | private <u>AccountType type</u>; | ||
private int balance; | private int balance; | ||
public Account (String number, AccountType type) { ... } | public Account (String number, AccountType type) { ... } | ||
// new Account("238497", AccountType.TEIKI); | // new Account("238497", AccountType.TEIKI); | ||
// new Account("238497", TEIKI); // import static pkg.AccountType.TEIKI; | |||
2019年7月3日 (水) 00:14時点における最新版
< Java基本文法
- 列挙型 (enum type) とは、フィールドに割り当てられる値(3つ以上)を列挙して限定する仕組み
- 2つだけなら三項演算子の boolean型の true と false で表現できる
- switch文などで活用できる
# AccountType.java
enum AccountType {
FUTSU, TOUZA, TEIKI;
}
public class Account {
private String number;
private AccountType type;
private int balance;
public Account (String number, AccountType type) { ... }
// new Account("238497", AccountType.TEIKI);
// new Account("238497", TEIKI); // import static pkg.AccountType.TEIKI;