var是一个可以多次赋值的数
val是附了值不可以改变的数
var followerPv=0
val children:List[TreeNode]=node.children
if (children !=null) {
followerPv += children.size
for (child <- children){
followerPv += findNodeFollowerPv(child)
}
此处代码无问题
val followerPv=0
val children:List[TreeNode]=node.children
if (children !=null) {
followerPv += children.size
for (child <- children){
followerPv += findNodeFollowerPv(child)
}
当两个数值都是val时 idea运行时会报错
故 var可以被赋予多次值 val再被赋值时就会被报错