Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to use types marked with the @Exported annotation introduced in Java 8?

Tags:

java

Java 8 introduced the @Exported annotation and its documentation states the following:

Indicates whether or not a JDK specific type or package is an exported part of the JDK suitable for use outside of the JDK implementation itself.

What is an exported part of the JDK? Should I use any types marked with such annotation? Is it considered safe?

For example, this annotation is present on the com.sun.net.httpserver.HttpServer class.

like image 916
cassiomolin Avatar asked Jul 27 '16 09:07

cassiomolin


People also ask

Which is the newly introduced Java annotation in Java 8?

Creating a Repeatable Annotation Java 8 has added a new annotation called '@Repeatable' in the 'java. lang. annotation' package to support annotations that can be repeated. Following the example above will define the 'Season' annotation with the '@Repeatable' annotation specified.

Which annotations can be used in Java 8?

With Java 8, annotations can now also be written on any use of a type such as types in declarations, generics, and casts: @Encrypted String data; List<@NonNull String> strings; myGraph = (@Immutable Graph) tmpGraph; At first glance, type annotations aren't the sexiest feature of the new Java release.

Which of the following is not a predefined annotation type in Java 8 standard library?

Correct Option: C. @Overriden is not a pre defined annotation in Java.

Can all the objects be annotated in Java 8?

As of the Java SE 8 release, annotations can also be applied to any type use. This means that annotations can be used anywhere you use a type. A few examples of where types are used are class instance creation expressions (new), casts, implements clauses, and throws clauses.


1 Answers

See its javadoc:

Indicates whether or not a JDK specific type or package is an exported part of the JDK suitable for use outside of the JDK implementation itself. This annotation should only be applied to types and packages outside of the Java SE namespaces of java.* and javax.* packages. For example, certain portions of com.sun.* are official parts of the JDK meant to be generally usable while other portions of com.sun.* are not. This annotation type allows those portions to be easily and programmatically distinguished.

So it's safe to use JDK-supplied classes annotated with that, but you should not be using that annotation in your own classes.

like image 98
eis Avatar answered Oct 22 '22 18:10

eis