作者:GloryWumie | 来源:互联网 | 2023-02-02 10:00
我想在kotlin中使用aspectj aop,这是我的代码:
我在annotation.lazy_list中的注释:
科特林:
package anotation
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class lazy_list
我的方面是一个类:
@Aspect
class ActiveListAop{
@Pointcut("execution(@annotation.lazy_list * *(..))")
fun profile() {
}
@Before("profile()")
fun testModeOnly(joinPoint: JoinPoint) {
println("123")
}
}
我的用法:
@lazy_list
fun all():List{
return lazy_obj?.all() as List
}
当我调用all()函数,没有错误,但不打印"123",为什么?
1> Jayson Minar..:
对于Kotlin中的注释过程,您必须启用并使用KAPT.如果没有通过Gradle或Maven插件添加,Kotlin代码中的注释处理将无法正常工作.
Kotlin插件支持Dagger或DBFlow等注释处理器.为了让他们使用Kotlin类,请应用kotlin-kapt插件.
也可以看看:
推动Kotlin注释处理的极限
kapt:Kotlin的注释处理
更好的注释处理:支持kapt中的存根