下面代码编译不过,如果改成if else就可以了,为什么?- public class WeekDay {
- private WeekDay(){}
-
- public final static WeekDay MON = new WeekDay();
- public final static WeekDay TUE = new WeekDay();
-
- public WeekDay nextDay()
- {
- if(this == MON)
- return TUE;
-
- if(this == TUE)
- return MON;
- }
-
- public String toString()
- {
- if(this == MON)
- return "this is Monday";
-
- if(this == TUE)
- return "this is Tuesday";
- }
- }
复制代码 |