Module Imports in Java 23 - Inside Java Newscast #69

preview_player
Показать описание
To reduce the overhead of using APIs, particularly in single source files, Java 23 previews module import declarations of the form `import module $moduleName, which import all packages exported by the named module.

~~~ Chapters ~~~

0:00 Intro
0:57 Star Imports
1:46 Module Imports
3:24 Module Import Details
4:48 More Modules?

Tags: #Java #Java23 #OpenJDK #InsideJava
Рекомендации по теме
Комментарии
Автор

I don't immediately think this will make a difference to adoption. I was enthusiastic about the module system when it was announced... until I saw it. Fine for library builders, a PITA for everybody else. I've literally never seen it used in projects anywhere, ever.

bentels
Автор

In Java, there are 3 levels of mandatory granularity: 1. Project (Gradle or Maven), 2. package, 3. class/interface/record. Everything is a member of all 3. In C/C++, on the other hand, there is no mandatory granularity, so you can create one giant mess, unless you impose strict guidelines. So, what happened, in my opinion, is that Java developers just consider these 3 levels of granularity plenty, especially if they come from C/C++, which is often the case.

mirzahadzic
Автор

Unpopular opinion: Java module system should have released during Java 7 timeframe, so adoption would have been great.
It got release at wrong time where everyone was busy with micro-services/docker/cloud.

Anbu_Sampath
Автор

Maybe I miss something here, but as you stated in the beginning, many Java developers are using explicit imports for each type they’re using within a compilation unit. I wouldn’t feel comfortable importing all of a module compared to explicitly documenting what is needed. Sure, prototyping is fine with it, but where would I benefit from the module system in production?

dubquery
Автор

I’m not really that interested in the imports section. It’s collapsed, it’s autosorted, it’s autocleaned, it’s autogenerated. If IDE wishes to use module imports, I’ll let it. If not, no big deal.

apinakapinastorba
Автор

Was really interested in that JEP once I saw it, like how it seems and will definitely try it out.

mm
Автор

I missing old java magazine where there was no youtube videos but articles was full of knowledge. And authors was focused on deliver good article without poor influence experience.

krzysztofempicki
Автор

I can see some situations where imwould replace star imports with modules. But they are typically for n not modularized test libraries

berndeckenfels
Автор

Java modules got caught in a chicken and egg scenario:
The demand isn't there because the major frameworks don't support it yet, but.. the major frameworkds don't support it yet cause there is no demand.
We use star imports currently in production code, and honestly it's fine. your IDE knows where your types are from and will happily show you whenever it becomes relevant, we'l probably start using this

shadeblackwolf
Автор

Module import will be good fro scripting and shell related usage. Just yesterday, I was showing to my kids on jshell where they wanted to calculate #days to birthday, and I had to import time, time.format, time.unit packages 😑 when I know it's all related to time. This would solve, but have to wait an year.

MrKar
Автор

I think I might use this update on java modules to write domain libraries...

parsaloi
Автор

Modules aren't used because they not useful to developers. They only really make sense in the JDK. If they had formalized dependency management on the other hand... Like why write import module in a script when I still have to somehow get that module into my class path???

theblackavenger
Автор

Only monsters use star imports in checked-in code. Monsters!

prdoyle
Автор

That’s nice, I wish I could import more flexibly like I can in Kotlin, Scala, or Rust. Renaming imports, renaming subsets, importing subsets, with sub-namespaces.

Nick-ydrc
Автор

Why not bring JEP 477 to all Java source files instead of just implicitly defined classes? It seems easy enough to make sure that code that compiled in Java 22 remains unaffected by the automatic module import, but perhaps I'm missing a corner case.

jay_
Автор

Wow Nicolai. You really promoting your own book on a IJN episode? Quite gauche.

billykorando
Автор

don't get or see any benefits, IDE is hiding imports, what the deal with add something by double click and choose right one?
I am 14 y in backend developing, lot of projects behind and nowhere modules were applied. useless for servers.

ITksh-zpob
Автор

After the explanation, I still fail to understand the point of this

CraccaHacka
Автор

Don't want to start any controversies, but to me - it looks like JDK community is doing same thing C++ community was (and still is) doing with their implementations - reinventing bike, but making it so, that it has squared wheels. I think, just like C++, JDK does not know what it wants to be and simply adds whatever features it can, which makes Java lose its identity. It's as if there was a huge leap between JDK6 and 8 and then between 8 and 17 and then from there - everything is pretty much either "syntactic sugar", or features that 99% of developers do not use, or will not use.

Yes - all these things are cool and all, but like modules - not practical. For modules, in particular, I think they would end up just dissapearing in several LTS iterations as no major platforms are using them. Guy, who commented here about - "wrong time-wrong place" (aka should have been part of JDK7) was spot on, in my opinion.
For imports, kind of same thing. I don't even remember the last time I have imported anything. My IDE does that for me automatically. The only thing I need to do each time I install it is to configure after how many imports it should replace each import from a same package with '*'.

In coporation I have been working - many people had common opinion, that in near future Java and JDK will only be used in major corporations as startups, mid-sized companies and etc look elsewhere (Go, Rust, etc...)

theobserver_
Автор

Popular opinion: Star imports are fine.

redorange