发信人: mxx(mxx), 信区: Java
标 题: Enum里函数返回一个同类object?
发信站: 饮水思源 (2014年11月02日00:02:13 星期天)

enum Direction {
left (1), down (2), right (3), up (0);

int d;
Direction(int d){ this.d =d;}

Direction oppositDir() {
return new Direction( (d+2)%4 );
}
}// Direction

oppositDir()报错: "Cannot instantiate the type Direction"
然后如果把new去掉还不行: "The method Direction(int) is undefined for the type
Direction"
应该怎么写呢?
--

※ 来源:·饮水思源 bbs.sjtu.edu.cn·[FROM: 129.104.247.2]