1
我观察到一个断言失败,我试图在下面进行描述。简而言之,当我调用重写的方法时,初始化的类成员虚假地变为空。成员变量为空,虚假?
abstract class A<T> {
T target
def something() {
assert target != null // sanity check -- fails when invoked below
return this
}
}
class B extends A<Something> {
static B makeB() {
def b = new B()
b.target = new Something();
assert b.target != null
return b
}
}
// package test
// Test code
//
def b = B.makeB() // <-- success.
assert b != null
assert b.target != null
b.something() // <-- fails assertion
print "Success!"
我有产生最小的测试用例的麻烦 - 在成功compileonline.com 但与我们在我们的机器代码(到位东西与龙)运行在上面。
的问题消失,如果我重新实现在子类B.
有没有人观察到了类似的效果something
方法?我已经非常沮丧了。
“Something”类在哪里?你能补充吗? – 2014-10-28 09:32:12
它恰好是一个Grails域对象 - 这是我不了解最小失败测试用例的地方。也许相关:A用Something和SomethingElse扩展(extends Something)。 – 2014-10-28 09:36:21
事实上,我在代码中用'Long'替换了'Something',并且发生了同样的故障。还没有找到一个独立失败的测试用例。 – 2014-10-28 09:50:50