setEqual()の意味がわからないのでそれを脇に置いておくと・・・
フィールドuserTypeの初期値がconstructorに与えられるが、superUserがあればそれを無視してuserTypeフィールドの値が決定されると考えるなら、例えば以下のようにする方法があると思います。
java
1public class User{
2 final User superUser;
3 final Integer userType;
4
5 public User(User superUser, Integer userType) {
6 this.superUser = superUser;
7 this.userType = superUser == null ? userType : superUser.userType;
8 }
9}
userTypeを参照するのにゲッターを用いることにし、このユーザー固有のuserTypeと親クラスによって決まるuserTypeの両方が使われることがあるという想定なら、以下のようにする方法もあると思います。
java
1public class User{
2 final protected User superUser;
3 final protected Integer userType;
4
5 public User(User superUser, Integer userType) {
6 this.superUser = superUser;
7 this.userType = userType;
8 }
9
10 public Integer getAdjustedUserType() {
11 return superUser == null ? userType : super.getAdjustedUserType();
12 }
13
14 public Integer getOwnUserType() {
15 return userType;
16 }
17}
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/14 06:31 編集