Reputation: 6109
Is an import statement inside a method purely a compile time construct, the same as an import statement declared outside of a class? From reading other questions I'm fairly certain it is just a compile time construct, but experience has taught me to be wary of things that I'm not 100% certain of. Also I was reading an article that I can no longer find that created a doubt about this. So particularly when I'm loading classes at runtime I want to make sure there are no subtle gotcha's with import statements inside methods /classes.
Upvotes: 2
Views: 1308
Reputation: 206796
Import statements are always purely a compile-time construct, no matter whether they are used inside a method, class, object or at top-level.
The only purpose of an import statement is to bring the names of whatever you are importing in scope, so that you don't have to type the fully-qualified names each time, which would make your code very verbose and unreadable.
Upvotes: 6