Aspectj无法与Kotlin一起使用 [英] Aspectj doesn't work with kotlin

查看:925
本文介绍了Aspectj无法与Kotlin一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在kotlin中使用Aspectj aop,这是我的代码:

i want to use aspectj aop in kotlin,here is my code:

我在annotation.lazy_list中的注释:

my annotation in annotation.lazy_list:

科特琳:

 package anotation

@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.FUNCTION)
annotation class lazy_list

我的aspectj aop类:

my aspectj aop class:

@Aspect
class ActiveListAop{

    @Pointcut("execution(@annotation.lazy_list * *(..))")
    fun profile() {

    }

    @Before("profile()")
    fun testModeOnly(joinPoint: JoinPoint) {
        println("123")
    }

}

我的用法:

 @lazy_list
    fun all():List<T>{
        return lazy_obj?.all() as List<T>
    }

当我调用all()函数时,没有错误,但不会显示"123",为什么?

when i call all() function , no error,but wont't print "123", why?

推荐答案

对于Kotlin中的注释过程,您必须启用并使用 KAPT .如果没有通过Gradle或Maven插件添加它,则Kotlin代码中的注释处理将无法正常工作.

For annotation process in Kotlin, you must enable and use KAPT. Without this being added via Gradle or Maven plugin, nothing is going to work for annotation processing in Kotlin code.

Kotlin插件支持Dagger或DBFlow之类的注释处理器.为了让他们使用Kotlin类,请应用kotlin-kapt插件.

The Kotlin plugin supports annotation processors like Dagger or DBFlow. In order for them to work with Kotlin classes, apply the kotlin-kapt plugin.

另请参阅:

  • Pushing the limits of Kotlin annotation processing
  • kapt: Annotation Processing for Kotlin
  • Better Annotation Processing: Supporting Stubs in kapt

这篇关于Aspectj无法与Kotlin一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆