In my practice as a Java programmer, I would have found the methods provided by classes such as sun.reflect.Reflection
or sun.misc.Unsafe
very useful in some cases, for example the ability to write caller-sensitive code. However, the use of sun.reflect
and related packages by application code is strongly advised against as it is not public API. What are the reasons that this functionality is not added to the Java Standard Library? Sometimes I get the impression that the Java API developers mistrust a programmer's ability to consider potential risks of these methods and make a conscious decision on when their use is reasonable.
Note: My question is not a duplicate of 'It is a bad practice to use Sun's proprietary Java classes?' There, the question is, why these classes should not be used. My question is why they are not added to the API which is 'good practice to be used'.