Skip to content
New issue

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

Kotlin 의 @JvmField 어노테이션 #152

Open
occidere opened this issue Dec 6, 2020 · 0 comments
Open

Kotlin 의 @JvmField 어노테이션 #152

occidere opened this issue Dec 6, 2020 · 0 comments
Assignees

Comments

@occidere
Copy link
Owner

occidere commented Dec 6, 2020

@JvmField

코틀린 컴파일러가 getter / setter 를 자동으로 생성하지 못하도록 막고, 그 대신 필드를 직접적으로 노출시켜 사용하도록 한다.

Example

예를들어 아래와 같이 location 프로퍼티에만 @JvmField 가 붙은 Corporation 클래스가 있다.

class Corporation(
        val name: String,
        @JvmField val location: String
)

이 클래스를 Java 에서 사용하는 경우 각 멤버에 접근할 때 아래와 같이 @JvmField 가 붙은 프로퍼티의 경우 .location 처럼 직접 접근해서 사용할 수 있는 것을 화인할 수 있다.

public static void main(String[] args) {
	Corporation naver = new Corporation("NAVER", "Seongnam-Si");

	String name = naver.getName(); // getXXX()
	String location = naver.location; // 직접 접근
}

참고

@occidere occidere self-assigned this Dec 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant