我正在使用Kotlin。我有两个spring类,com.example.SpringConfigA
和com.example.SpringConfigB
。我试图将它们导入到com.example.SpringConfigParent
中,但以下都不起作用:
尝试1,错误:This annotation is not repeatable
@Import(com.example.SpringConfigA)
@Import(com.example.SpringConfigB)
class SpringConfigParent {}
尝试2,错误:Type mismatch: inferred type is () -> ??? but KClass<*> was expected
@Import({com.example.SpringConfigA, com.example.SpringConfigB})
class SpringConfigParent {}
尝试3,错误:Only 'const val' can be used in constant expressions
@Import(arrayOf(com.example.SpringConfigA, com.example.SpringConfigB))
class SpringConfigParent {}
在Kotlin中,正确的语法是什么?
**编辑:**正如@jaquelinep建议的那样,我忘记添加::class
,尝试使用它:
尝试1,错误:This annotation is not repeatable
@Import(com.example.SpringConfigA::class)
@Import(com.example.SpringConfigB::class)
class SpringConfigParent {}
尝试2,错误:Type mismatch: inferred type is () -> KClass<SpringConfigA> but KClass<*> was expected
@Import({com.example.SpringConfigA::class, com.example.SpringConfigB::class})
class SpringConfigParent {}
尝试3,错误:Type inference failed. Expected type mismatch: inferred type is Array<KClass<out Any>> but KClass<*> was expected
@Import(arrayOf(com.example.SpringConfigA::class, com.example.SpringConfigB::class))
class SpringConfigParent {}
2条答案
按热度按时间odopli941#
带有一个注解的多个导入的语法如下:
w1jd8yoj2#
您在类名末尾缺少.class:
我更新了答案感谢eamon-scullion