Import efficiency

C

Crouchez

Is importing a class directly ie.

import java.io.InputStream

more efficient than

import java.io.*;

?

What happens? Does the JVM import all the classes if using a wildcard?
 
S

Stefan Ram

Crouchez said:
more efficient than

There is run-time efficiency, memory efficiency, disk usage
efficiency ...
What happens? Does the JVM import all the classes if using a wildcard?

An import declaration allows a static member or a named type
to be referred to by a simple name that consists of a single
identifier. I don't think that the JVM is aware of it at all.
 
M

Mark Rafn

Crouchez said:
Is importing a class directly ie.
import java.io.InputStream
more efficient than
import java.io.*;

It has no effect on the generated class, so no effect on runtime efficiency.
It's probabaly a hair faster to compile.

As a developer, I prefer specific imports, as it's easy to expand a classname
if the import is there, rather than having to search through a bunch of
packages to see where SomeFooAccessor is defined.
What happens? Does the JVM import all the classes if using a wildcard?

No. The JVM doesn't see imports. They're thrown away by the compiler. The
compiler uses them to replace short type names with fully-qualified names.
There is no bytecode difference between importing specific names, wildcards,
and not importing anything in favor of using fully-qualified names everywhere.
 
A

Arne Vajhøj

Stefan said:
An import declaration allows a static member or a named type
to be referred to by a simple name that consists of a single
identifier. I don't think that the JVM is aware of it at all.

I don't think he asked for static import just plain import.

Arne
 
A

Arne Vajhøj

Lew said:
The answer is the same for both domains of discourse - there is no
run-time impact.

Yep.

But maybe the original poster were a bit confused by the explanation.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top