Hi there, I was playing with the code on page 12 of the OCA 8 Guide. I've tested in fact the code does not compile for the following code, due to conflicting class in both packages:
My question: However, I then tried the code in the example below, and while it still does not compile if you specify to import the Date class... it does compile with no problems when you import both packages with the wildcard. Why?
Thanks in advance,
--------- import with specific class --------- does not compile
"error: a type with the same simple name is already defined by the single-type-import of Date
Great question! The rule of thumb is that Java needs one of the classes to be fully qualified to know what should be considered most important. In your second example, you try to specify both so Java doesn't know what to do.
The third example, uses Random which is only in one package so doesn't have a conflict anyway.