不确定在一行Java代码中“set”在做什么
set这行代码是什么意思?
List<SimpleGrantedAuthority> authorities = set = new ArrayList<>();
我试图找出这意味着什么,但到目前为止还没有运气。
回答
这本质上是链式赋值。a = b取值为b, 并且=是右结合的,所以代码等价于:
List<SimpleGrantedAuthority> authorities = (set = new ArrayList<>());
这相当于:
set = new ArrayList<>();
List<SimpleGrantedAuthority> authorities = set;
请注意,要使其正常工作,set必须事先使用正确的类型声明。
- Another way to say this is that the assignment operator has a return value, namely the value having been assigned.
- While I totally agree with the answer, I have to say that naming an `ArrayList` as `set` in Java is sadistic.