Having programmed in Groovy quite a bit I know classes in certain packages are automatically imported. What's the scoop for 1) Java and 2) Groovy? Is there a definitive list of ones you don't need to specify an import for for each of these languages?
java. lang package is automatically imported.
While in every program Collection classes are not used while basic datatypes are essential for every java program. To avoid unnecessary load of other classes in program other packages are not auto imported while essential package java. lang is auto imported.
In order to refer to any class you need a qualified reference to its package. Groovy follows Java's notion of allowing import statement to resolve class references.
No you will have to import the subpackages explicitly. Importing com. MyTest. * will import classes in the package MyTest only.
In Java, the only package imported by default is
java.lang.*
This is where objects such as String and Object reside.
According to here, the list of packages for groovy are
java.io.*
java.lang.*
java.math.BigDecimal
java.math.BigInteger
java.net.*
java.util.*
groovy.lang.*
groovy.util.*
AFAIK, java only imports
java.lang.*
wheras groovy imports:
java.io.*
java.lang.*
java.math.BigDecimal
java.math.BigInteger
java.net.*
java.util.*
groovy.lang.*
groovy.util.*
According to https://groovy-lang.org/differences.html#_default_imports
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With