Reputation: 4107
Is it possible to call the JVM's built-in native code, i.e. the code that various class in java.lang and java.io call? In other words, can you bypass the built-in java API to access various system-level calls such as file-system access? I know I could do this by building my own native code library and calling that via JNI, but it would be elegant to not need an extra native library for functionality already built into the JVM.
Upvotes: 1
Views: 941
Reputation: 147134
You can, of course, use reflection to call the methods providing the code is trusted. However, the non-public APIs are liable to change between updates and implementations, so pretty much pointless and absolutely non-elegant.
Upvotes: 0
Reputation: 83011
No you can't. It's designed that way on purpose; you would override the API contracts if you could.
In any event, the standard library wrapper code is very slight and with JIT compilers you shouldn't notice any speed impact.
Furthermore, the implementation of those methods are not part of the API spec. What is "native" for one implementation of Java doesn't have to be for another.
Upvotes: 6