I am just playing with package structure. And to my surprise I can bypass the default classes by creating my package and class name with that name.
For ex:
I created a package called java.lang
and Class is Boolean
. When I import java.lang.Boolean
it's not the JDK's version of Boolean
. It's mine. It's just showing the methods of Objects
which every object java have.
Why so ? Why I am allowed to create the package java.lang
? And the program runs fine.
Another baffle is if I create a Class
with name Object
and try to runs the program then an exception
java.lang.SecurityException: Prohibited package name: java.lang
at java.lang.ClassLoader.preDefineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
Why is this behaviour ? is this a bug or normal behaviour ?