We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@JvmMultifileClass
@JvmName 과 함께 사용되며, top-level 함수가 여러 파일이 걸쳐 선언되어 있을 때 마치 하나의 파일에 선언되어 있는 것 처럼 사용하고 싶을 때 사용한다.
@JvmName
예를들어 아래의 2개 파일이 각각 존재한다.
/* 파일 1: StringPrintUtils.kt */ fun printAllStrings(list: List<String>) { println(list) } /* 파일 2: IntPrintUtils.kt */ fun printAllInts(list: List<Int>) { println(list) }
이 때, 두 파일 내 함수들에 접근 시 각 파일명이 아닌, Utils 와 같은 동일한 이름으로 접근하고 싶다고 하자.
Utils
public static void main(String[] args) { /* AS-IS */ IntPrintUtilsKt.printAllInts(Arrays.asList(1, 2, 3)); // ok StringPrintUtilsKt.printAllStrings(Arrays.asList("a", "b", "c")); // ok /* TO-BE */ Utils.printAllInts(Arrays.asList(1, 2, 3)); // compile error Utils.printAllStrings(Arrays.asList("a", "b", "c")); // compile error }
이와 같은 경우 각 파일에 @file:JvmName, @file:JvmMultifileClass 어노테이션을 붙여주면 가능하다.
@file:JvmName
@file:JvmMultifileClass
/* 파일 1: StringPrintUtils */ @file:JvmName("Utils") @file:JvmMultifileClass fun printAllStrings(list: List<String>) { println(list) } /* 파일 2: IntPrintUtils */ @file:JvmName("Utils") @file:JvmMultifileClass fun printAllInts(list: List<Int>) { println(list) }
이후 원하는 방식대로 사용할 수 있다.
public static void main(String[] args) { /* AS-IS */ IntPrintUtilsKt.printAllInts(Arrays.asList(1, 2, 3)); // compile-error StringPrintUtilsKt.printAllStrings(Arrays.asList("a", "b", "c")); // compile-error /* TO-BE */ Utils.printAllInts(Arrays.asList(1, 2, 3)); // ok Utils.printAllStrings(Arrays.asList("a", "b", "c")); // ok }
The text was updated successfully, but these errors were encountered:
occidere
No branches or pull requests
@JvmMultifileClass
@JvmName
과 함께 사용되며, top-level 함수가 여러 파일이 걸쳐 선언되어 있을 때 마치 하나의 파일에 선언되어 있는 것 처럼 사용하고 싶을 때 사용한다.Example
예를들어 아래의 2개 파일이 각각 존재한다.
이 때, 두 파일 내 함수들에 접근 시 각 파일명이 아닌,
Utils
와 같은 동일한 이름으로 접근하고 싶다고 하자.이와 같은 경우 각 파일에
@file:JvmName
,@file:JvmMultifileClass
어노테이션을 붙여주면 가능하다.이후 원하는 방식대로 사용할 수 있다.
참고
The text was updated successfully, but these errors were encountered: