5

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?

1
  • allowing of the value being cached which eliminated the expensive call to get the value Nov 15, 2013 at 14:33

3 Answers 3

4

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.

0

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.

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.