ND27
ND27

Reputation: 437

Groovy code - import statement not needed?

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.

Upvotes: 6

Views: 1588

Answers (2)

M A
M A

Reputation: 72844

No imports are not inherited between classes.

In Groovy all of the below packages are imported by default.

  • java.io.*
  • java.lang.*
  • java.math.BigDecimal
  • java.math.BigInteger
  • java.net.*
  • java.util.* (which includes Collection)
  • groovy.lang.*
  • groovy.util.*

Upvotes: 8

Opal
Opal

Reputation: 84756

Have a look at default imports. This is expected behavior. There's no import inheritance. All these packages are imported for every class.

Upvotes: 3

Related Questions