From the course: Java 25 for Professionals with Jetbrains AI Assistant
Simplifying modular Java - Java Tutorial
From the course: Java 25 for Professionals with Jetbrains AI Assistant
Simplifying modular Java
- [Instructor] Before Java 25, we wrote long lists of imports for individual types, and we just kept on adding and adding if we wanted more Java libraries. Well, guess what? The future is here. We can now import an entire module with a single line, such as import module java.base. Bam, all the Java goodies are here. That one line, import module java.base, makes all public types from the packages exported by Java base available for simple-name use. We can do that now without writing dozens of import statements. It brings java.util, io, nio, and so on. However, because we're importing huge chunks, we can get name clashes. Look at this. If I uncomment this Date, it is now ambiguous. Why? Well, because both java.sql.date and java.util.date are matching. So, whoops, we have two dates now. And we need to fix it. We either qualify the name, java.sql.date, or add a specific single-type import, import java.sql.date. So, this is one way to fix it. (keyboard clicking) And this is the other. (keyboard clicking)