Jump to content

import using *

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
My question is not so much a problem as a curiosity. I was under the impression that the * would load everything in a package. For example when I use java sound I use


import javax.sound.*;



however when I did this today it still required me to import each part of the sound package that i wanted to use


import javax.sound.midi.MidiEvent;

import javax.sound.midi.MidiSystem;

import javax.sound.midi.Sequence;

import javax.sound.midi.Sequencer;

import javax.sound.midi.ShortMessage;

import javax.sound.midi.Track;


It doesn't matter two much sense eclipse will auto add most of the imports but in a real app this is going to leave me with a LONG list of imports. The book I am reading told me to use the * and just have the one import and that seems the best method to me. Is there a reason why just using the first example up there will not compile?
Posted Image

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
The wildcard only makes the classes in the single package visible, not any of the subpackages, there would be possible problems with recursive symbol lookup by the compiler
import javax.sound.midi.*

Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#3
zeroradius

zeroradius

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,406 posts
Thanks Nullw0rm. That makes sense. Now that i look back at the book it told me to do it like you did it. I was trying not to look to much at the example when i wrote the code and i did not understand about the sub packages. +rep
Posted Image