我有以下代码:斯卡拉正确使用破返回
private def hasRole(role: String): Boolean = {
var hasRole = false;
if(getUserDetails.isDefined){
// getAuthorities returns java.util.Collection<GrantedAuthority>
val authorities: util.Collection[_ <:GrantedAuthority] = getUserDetails.get.getAuthorities
// Wrap the collection is a Scala class
val authoritiesWrapper = JCollectionWrapper.apply(authorities);
for(authority <- authoritiesWrapper.iterator){
if(authority.getAuthority == role){
hasRole = true;
scala.util.control.Breaks.break
}
}
}
hasRole
}
的问题是,是scala.util.control.Breaks.break
正确的方式return
当我发现的作用?看起来并不适合我。
那么,首先,你还没有设定休息的范围。你需要有一个'breakable {}'子句来围绕你将要破解的代码。 – adchilds
另外_ <:GrantedAuthority是什么意思?我从IntelliJ的代码中得到了这一点。 < - 作为单独的问题发布。我正在从这个中删除。 – djechlin