JailedBird/ArouterKspCompiler

在泛型类使用 @Autowired 注解编译报错

QasimCyrus opened this issue · 2 comments

如图,编写一个带有类型参数的泛型类,里面使用了 @Autowired 注解:
编写测试类

编译过程中报错,提示缺少泛型参数:
生成类缺少泛型

问题定位:
问题定位

感谢指出问题,修复方案如下:

image

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!"
         )

见README最新版本,请更新到xxx-1.0.4