Alan Couze wrote:In Chapter 1 it explains that the following import statement is not valid when you want to import java.nio.file.Files and java.nio.file.Paths:
That's indeed correct! The wildcard notation will
not work with sub-packages.
Alan Couze wrote:However, I tried creating a couple of test packages and an import such as this seemed to work.
Based on your code you are not using any packages at all, because I don't see any package statement in your code. Without a package statement your class will be defined inside the
default package. Adding a package statement is very easy
Alan Couze wrote:The example above does error out by saying "MyTest.java:1: error: package test1 does not exist". However, if I add any Class to the test1 directory (i.e. "Test1") then the above compiles without error. So, it seems to me that the wildcard for imports will work correctly with sub-packages (i.e. test1.test2) but only if there are Classes in the parent package(s) (test1).
Is this a correct assumption?
No, it isn't! When you correctly use packages in your code, you'll discover the statement in the study guide is spot-on and a wildcard doesn't work for sub-packages.
Hope it helps!
Kind regards,
Roel