android - 从阴影方法调用真实对象的方法会导致无限递归
问题描述
我创建了一个调用真实对象的影子类,如http://robolectric.org/extending中所述:
@Implements(View::class)
class MyShadowView {
@RealObject
private lateinit var realView: View
@Implementation
fun animate(): ViewPropertyAnimator {
return realView.animate() // this call ends up calling my shadow's animate() function recursively
}
}
但是,当我的影子方法被执行时,它会导致无限递归。
我究竟做错了什么?
(我使用的是 Robolectric 4.2。)
解决方案
根据http://robolectric.org/javadoc/4.1/org/robolectric/shadow/api/Shadow.html它应该是这样的:
@Implementation
fun animate(): ViewPropertyAnimator {
Shadow.directlyOn(realView, View::class.java).animate()
}
推荐阅读
- bash - 连接多行日志条目
- express - 访问 req.session.variable 方法时出错
- vue.js - 在响应 JSON 数据的初始加载时不调用观察者的最佳实践是什么
- apache-spark - Spark 总内存分配
- c# - 在 ASP.NET Core 2.1 中设置选定选项
- protractor - 量角器:在期望失败时截取屏幕截图
- c# - 使用 Web API 上传附件后读取响应
- python - 使用权重减少数据框
- node.js - 在 Meteor 1.7.0.4 中升级 MongoDB 驱动程序
- jenkins - 使用 curl/REST api 从 jfrog 工件下载大型存储库的替代方案