문제

link : http://download.java.net/jdk8/docs/api/java/lang/annotation/Native.html

In Java 8, there will be @Native annotations.

Indicates that a field defining a constant value may be referenced from native code. The annotation may be used as a hint by tools that generate native header files to determine whether a header file is required, and if so, what declarations it should contain.

Problem is: What for? Do you have any idea on which problematics would be efficiently solved by this feature?

도움이 되었습니까?

해결책

Imagine a header which defines constants to be used in messaging. One party of the conversation might be developed in C++, and they'd like to #include a header. Now maintaining two similar but separate files is a risk; deriving the C++ header from @Native constants is safer.

다른 팁

A good example is the serialVersionUID which is @native for java 8 classes.

This way, we make sure that an extension of a java program is able to refer to the serial version uid easily hence make sure we refer to the right classes.

I see 2 reasons: 1. Java implementation of "boxing" classes for low level API's like CUDA - managing single Interface which declares all low level API constants is much safer than managing both Java and header files over different low level API versions. 2. I would like to have also separate annotation for static factory methods like getInstance(). It can serve some very popular design patterns. The corresponding JNI code can be easily generated but it is very verbouse and not reliable when coded manually.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top