Some classes in the standard Java API are treated slightly different from other classes. I\'m talking about those classes that couldn\'t be implemented without special support f
Class
, of course. It has its own literals (a distinction it shares with String
, BTW) and is the starting point of all that reflection magic.
Not sure about this. But I cannot think of a way to manually implement IO objects.
There are a lot of different answers, so I thought it would be useful to collect them all (and add some):
Note: I left out of the list things that provide JNI (such as IO) because you could always implement your own JNI call if you were so inclined. However, native calls that interact with the JVM in privileged ways are different.
Arrays are debatable - they inherit Object, have an understood hierarchy (Object[] is a supertype of String[]), but they are a language feature, not a defined class on its own.
Well since the special handling of assert has been mentioned. Here are some more Exception types which have special treatment by the jvm:
The exceptions are not special, but the jvm uses them in special cases, so you can't implement them yourself without writing your own jvm. I'm sure that there are more special exceptions around.
There is some magic in the System
class.
System.arraycopy
is a hook into native code
public static native void arraycopy(Object array1, int start1,
Object array2, int start2, int length);
but...
/**
* Private version of the arraycopy method used by the jit
* for reference arraycopies
*/
private static void arraycopy(Object[] A1, int offset1,
Object[] A2, int offset2, int length) {
...
}
All of the Number classes have a little bit of magic in the form of Autoboxing.