Since java.lang
package is automatically imported in all java programs by compiler, why is it necessary to write import java.lang.annotation;
statement at the top of the program while using annotations in the program?
Because the java.lang.annotation
package isn't the same as the java.lang
package. They're simply different packages.
Imagine if importing one package imported all the packages "under" it - then
import java.*;
would import almost everything in the standard libraries - but that's not the way it works. An import statement of
import foo.*;
simply imports all the types in the foo
package - it doesn't import anything in any other packages which happen to start with foo.
.
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