I created a groovy class with a method that returns Collection<String>
. It works, but it's weird that there is no Collection
in the import statements.
The class inherits a super class. That super class (java) does have the import statement for collection: import java.util.Collection;
Is it the expected behavior?
Does java or groovy inherit imports too? I doubt that.
Import statement in Java is helpful to take a class or all classes visible for a program specified under a package, with the help of a single statement. It is pretty beneficial as the programmer do not require to write the entire class definition. Hence, it improves the readability of the program.
A simple import is an import statement where you fully define the class name along with the package. For example the import statement import groovy. xml. MarkupBuilder in the code below is a simple import which directly refers to a class inside a package.
The import statement is optional in Java. If you want to use class/interface from a certain package, you can also use its fully qualified name, which includes its full package hierarchy. Here is an example to import a package using the import statement.
[:] creates an empty Map. The colon is there to distinguish it from [] , which creates an empty List. This groovy code: def foo = [:]
No imports are not inherited between classes.
In Groovy
all of the below packages are imported by default.
Collection
)Have a look at default imports. This is expected behavior. There's no import inheritance. All these packages are imported for every class.
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