import * ?

Hello,Little question: what is the disadvantage doing an import * instead of a import of the precise class we need.For example, if I'm using only a Hashtable, is this really bad to do an import java.util.*; instead of an import java.util.*; ?ThanksLudovic
[291 byte] By [ludovicmaillet] at [2007-9-30 19:28:57]
# 1

I import like this and out of interest I decompiled a class of mine to see what java does with the import java.util.* or equivalent and I found that in the decompiled source code, it listed only the classes that it needed. (In this case java.util.Vector). I use the .* simply because my imports would be huge if I didn't!

Cheers,

Rachel

RachelSwailes at 2007-7-6 23:42:46 > top of Java-index,Administration Tools,Sun Connection...
# 2

> Little question: what is the disadvantage doing an

> import * instead of a import of the precise class we

> need.

> For example, if I'm using only a Hashtable, is this

> really bad to do an import java.util.*; instead of an

> import java.util.*; ?

>

It has absolutely no impact on the generated code.

From the maintainance perspective it is easier for a maintainer to tell where a class is coming from if you explicitly list it.

jschell at 2007-7-6 23:42:46 > top of Java-index,Administration Tools,Sun Connection...
# 3

import packageName.*;// type-import-on-demand

import packageName.ClassName;// single-type-import

import packageName.InterfaceName;// single-type-import

1. a single-type import will take precedence over an import-on-demand

2. import-on-demand types do not increase the size of the compiled code ie only the types actually used are added to the code

3. while import-on-demand adds no overhead to the compiled code, they can slow down the speed of the compile

this'll explain all

\/

http://developer.java.sun.com/developer/TechTips/2000/tt0110.html#tip2

/\

hope it did

kapilChhabra

kapilChhabra at 2007-7-6 23:42:46 > top of Java-index,Administration Tools,Sun Connection...