解决方法
最后有感叹号的方法通常被称为爆炸方法.爆炸方法不一定修改其接收器,并且不保证没有感叹号的方法不会.
这在this blog post年都很好解释.引用帖子:
The ! in method names that end with !
means,“This method is dangerous”—or,
more precisely,this method is the
“dangerous” version of an otherwise
equivalent method,with the same name
minus the !. “Danger” is relative; the
! doesn’t mean anything at all unless
the method name it’s in corresponds to
a similar but bang-less method name.
和
The ! does not mean “This method changes its receiver.” A lot of “dangerous” methods do change their receivers. But some don’t. I repeat: ! does not mean that the method changes its receiver.