Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
QasimCyrus opened this issue Aug 25, 2023 · 2 comments
Closed

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

QasimCyrus opened this issue Aug 25, 2023 · 2 comments

Comments

@QasimCyrus
Copy link

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

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

问题定位:
问题定位

@JailedBird JailedBird reopened this Aug 28, 2023
@JailedBird JailedBird pinned this issue Aug 28, 2023
@JailedBird
Copy link
Owner

JailedBird commented Aug 28, 2023

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

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

@JailedBird
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants