0

I don't find any references in JDK 7 documentation regarding sun.* packages. Is it deprecated. But then what are the substitutes?

For eg: sun.reflect.*; is deprecated, so what are the options now?

It would be great if someone could post the deprecated packages and the new options available.

Note: I succeded in using them by setting access rules to all available. enter image description here

What does this mean?

John Eipe
  • 10,922
  • 24
  • 72
  • 114
  • Why would you need them? Are you trying to implement caller sensitive behavior? – Antimony Mar 31 '14 at 14:27
  • As far as I know, the `sun.*` packages were never officially released, so if you're using them they may vary between releases. – rm5248 Mar 31 '14 at 14:29

2 Answers2

1

You have to use the java.lang.reflect package for reflection purposes.

See: http://docs.oracle.com/javase/8/docs/api/java/lang/reflect/package-summary.html

bobbel
  • 3,327
  • 2
  • 26
  • 43
  • I don't see a substitute for sun.reflect.ReflectionFactory. – John Eipe Mar 31 '14 at 14:33
  • 1
    The question is, what do you want to do with this `ReflectionFactory` what you cannot achieve with the things out of the `java.lang.reflect` package? – bobbel Mar 31 '14 at 15:06
1

The sun.reflect packages are not deprecated. They are for internal use by the JDK only. Oracle (formerly Sun) does not document the internal packages and does not guarantee that they will exist on all Java platform implementations (any vendor can make a Java platform implementation) nor that they will be the same in all versions of the standard Oracle Java platform implementation.

Oracle explains this on their website:

The sun.* packages are not part of the supported, public interface.

A Java program that directly calls into sun.* packages is not guaranteed to work on all Java-compatible platforms. In fact, such a program is not guaranteed to work even in future versions on the same platform.

Erwin Bolwidt
  • 30,799
  • 15
  • 56
  • 79
  • are there any other packages? with similar fate? – John Eipe Mar 31 '14 at 14:35
  • On the page linked in my answer it also says: "The java.*, javax.* and org.* packages documented in the Java Platform Standard Edition API Specification make up the official, supported, public interface." so anything outside those 3 packages, including "com.sun.*" is not supported. – Erwin Bolwidt Mar 31 '14 at 14:40
  • Here's the Javadoc of ReflectionFactory from the OpenJDK 1.7 source code: http://www.docjar.com/docs/api/sun/reflect/ReflectionFactory.html – Erwin Bolwidt Mar 31 '14 at 14:41
  • What do you want to do with ReflectionFactory that is not part of the normal reflection API? – Erwin Bolwidt Mar 31 '14 at 14:41
  • a little hacking... ;-) – John Eipe Mar 31 '14 at 14:48
  • 2
    Why didn't you say so? ;-) Have a look at [sun.misc.Unsafe](http://www.docjar.com/docs/api/sun/misc/Unsafe.html) when you get bored with reflection ;-) – Erwin Bolwidt Mar 31 '14 at 14:51