在泛型类使用 @Autowired 注解编译报错
QasimCyrus opened this issue · 2 comments
QasimCyrus commented
JailedBird commented
感谢指出问题,修复方案如下:
Test case:
+interface TestInterface1
interface TestInterface2
abstract class AbstactGenericAcitivty1<T : TestInterface1> : AppCompatActivity() {
@Autowired
var list = mutableListOf<String>()
}
abstract class AbstactGenericAcitivty2<T : TestInterface1, G:TestInterface2> : AppCompatActivity() {
@Autowired
var list = mutableListOf<String>()
}
@Route(path = "/app/TestAbstactGenericAcitivty1")
class TestAbstactGenericAcitivty1 : AbstactGenericAcitivty1<TestInterface1>(){
@Autowired
var t = mutableListOf<String>()
}
@Route(path = "/app/TestAbstactGenericAcitivty2")
class TestAbstactGenericAcitivty2 : AbstactGenericAcitivty2<TestInterface1, TestInterface2>(){
@Autowired
var t = mutableListOf<String>()
}
结果:
val substitute = (target as? AbstactGenericAcitivty1<*>)?: throw IllegalStateException(
"The target that needs to be injected must be AbstactGenericAcitivty1, please check your code!"
)
val substitute = (target as? AbstactGenericAcitivty2<*, *>)?: throw IllegalStateException(
"The target that needs to be injected must be AbstactGenericAcitivty2, please check your code!"
)
JailedBird commented
见README最新版本,请更新到xxx-1.0.4