【发布时间】:2018-06-01 14:36:32
【问题描述】:
我在Groovy 中使用Spock framework 编写了简单的测试
class SimpleSpec extends Specification {
def "should add two numbers"() {
given:
final def a = 3
final b = 4
when:
def c = a + b
then:
c == 7
}
}
变量a 是使用def 和final 关键字组合声明的。变量 b 仅使用 final 关键字声明。
我的问题是:这两个声明之间有什么区别(如果有的话)?应该将一种方法优先于另一种方法吗?如果有,为什么?
【问题讨论】: