文件类的注释

问题描述 投票:1回答:1

在我当前的代码(Java)中,我正在使用类级Java注释进行一些自定义注释处理,即注释是@java.lang.annotation.Target({ElementType.TYPE})

目标类只包含静态实用程序方法,因此我在Kotlin中使用了文件范围的函数。如何将这些注释添加到生成的Kt类中?

在Java中:

// Utils.java

package com.example;

@MyCustomAspect
public void Utils {

    public static void doStuff() {
        System.out.println("Hello";
    }
}

现在在Kotlin:

// Utils.kt

package com.example;

// ??? @MyCustomAspect ???

fun doStuff() {
    System.out.println("Hello";
}
annotations kotlin static-methods
1个回答
1
投票

您可以使用AnnotationTarget.FILE来允许Kotlin定义的注释来定位从Kt文件生成的.kt类。使用目标ElementType.TYPE定义Java注释也可用于定位Kotlin文件类:

@file:MyCustomAspect

package org.example

@Target(AnnotationTarget.FILE)
annotation class MyCustomAspect

fun doStuff(){

}
© www.soinside.com 2019 - 2024. All rights reserved.