2017-12-31 24 views
1

사용자 정의 단검 범위 생성을 위해 Java 코드를 Kotlin으로 변환하려고합니다. 필수 유형은 AnnotationRetention은 다음과 같습니다사용자 정의 대거 만들기 2 Kotlin으로 범위

@Documented 
@Scope 
@Retention(RetentionPolicy.RUNTIME) 
public @interface CustomScope { 
} 

일단 코 틀린로 변환 여기에 결과 내가 @Retention(RetentionPolicy.RUNTIME) .I와 형식이 일치하지가

@Scope 
@Documented 
@Retention(RetentionPolicy.RUNTIME) annotation class CustomScope 

다음과 같은 오류 메시지가이 : 여기

자바 코드 RetentionPolicy 유형이 발견되었습니다.

또한 @interface가 대체 된 것처럼 보입니다.

답변

3

사용했을 가능성이있는 Retention 주석 클래스는 Kotlin의 라이브러리 (패키지 kotlin.annotation)에서 가져온 것입니다.

enum 유형의 속성 AnnotationRetention이 필요합니다. 당신이 Annotations.kt 파일을 보면

@MustBeDocumented 
@Scope 
@Retention(AnnotationRetention.RUNTIME) 
annotation class CustomScope 

, BTW, 당신은 당신이 그것을 아무것도 통과하지 못한 경우 Retention 주석이 기본 속성 AnnotationRetention.RUNTIME를 취할 것이라는 점을 것을 볼 수 있습니다 : 그래서, 당신은 이런 식으로 뭔가를 할 수 있습니다.

따라서 @Retention 주석도 사용합니다.