We know java.lang
is the default package in java, and we don't need to import anything from them.
java.lang
?java.lang
? java.lang
with any other package (I mean, If I
re-write all the classes and interfaces from java.lang
to
java.lang1
, then can I set java.lang1
as default) ?I'm sure enough that all of these are not possible to just post, "no, these are not possible." Note you can't do it with reflection since these are all compile-time questions.
(4), "can I change the default base class from Object," is not like the others, and is the most ludicrous. That would break many many programs at compile, because even doing something like System.out.println(user)
relies on the fact that the object user
has a toString
method. In particular String
is broken, because its toString
method is inherited from Object
.
Everything else you asked is compile-time only, so less ludicrous, but still not possible.
For completeness, it also would be strange and bad practice. I've heard of a C programmer who included #define retrun return
in a headers file. So when any other developer maintaining his code saw retrun eta;
they had to dig out the headers file to know what it meant. This is write-optimized code but software engineering is about read-optimizing code (yes I'm generalizing; trying to cover this in a paragraph). Cluttered imports do that - it makes it very obscure to tell where things come from, which is fine for String
and Exception
, but problematic even for things in java.util
. Yes, this line was arbitrary at some point, but I feel it's intelligent and certainly should not include more things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With