1. I think the idea is, that if the older java.util.Date family of
   classes gets auto-imported, then its newer counterpart should also
   be, which makes sense to me.
    1. (As I understood it,  java.time.format & java.time.temporal
       would be auto-imported under the proposal (?))
2. I do however see the problem of where to draw the line with regards
   to other often used java.* packages (not related to the date-time
   domain).
    1. Perhaps instead of auto importing more and more packages, Groovy
       could:
        1. Issue a special kind of error if a script does not compile
           and it finds class names that match ones from well known /
           often used Java packages.
            1. The error message could include the required import
               statements ready to copy into the script, if the user so
               chooses.
                1. That would evidently not solve the "single line
                   Groovy script" case, but how many people actually
                   use Groovy that way... ?
                2. Single-line usage is always very limited in any case.
            2. Support "compound imports", analogue to existing
               AnnotationCollector for annotations.
                1. e.g.:
                    1. import all java // all but the most obscure Java
                       libs
                    2. import all java_core // all often used Java libs
                    3. import all datetime // all DateTime related libs
                    4. import all text // all text realted libs
                    5. etc
            3. Groovy then could come with some predefined "compound
               imports" like in the examples given above, as well as
               letting people define their own...

Cheers,
mg


Am 01.06.2025 um 14:56 schrieb Alexander Veit via users:
Am 31.05.25 um 09:36 schrieb Paul King:
We have a feature request, and potential PR, to add java.time.* as a
new default import:

https://issues.apache.org/jira/browse/GROOVY-11513
https://github.com/apache/groovy/pull/2156

I would vote against this proposal. Here are some arguments why:

First of all, I'm generally not in favor of adding more default default imports to the language, since I suspect negative impacts on maintainability of scripts and the efficiency of the compilation process.

Apart from Instance, LocalDateTime and ZonedDateTime most of the classes in java.time are probably rarely used. Does this justify to add 16 extra classes?

The classes in java.time are not fully usable without classes from other packages like java.time.format or java.time.temporal which should then also be default imports.

There are many good points about including such a star import

This argument also holds for other packages like java.nio.* or java.text.


Reply via email to