Results 1 to 4 of 4
Thread: Augustus Gloop or Twiggy?
- 07-29-2011, 06:26 PM #1
Senior Member
- Join Date
- Jul 2011
- Posts
- 100
- Rep Power
- 0
Augustus Gloop or Twiggy?
Is this (gen'd via Ctrl+Shift+O in Eclipse):
better than this:Java Code:import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.io.DataInputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.LineNumberReader; import java.io.OutputStream; import java.net.Socket; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.ScrollPaneConstants; import javax.swing.Timer;
Java Code:import java.io.*; import java.net.*; import javax.swing.*; import java.awt.*; import java.awt.event.*;
- 07-29-2011, 07:21 PM #2
I wondered that for years. But recently I ran into a situation where two classes from different packages had the same name. If I were importing the entire packages, I'd have to use the FQ name everywhere, thereby defeating the purpose of import statements.
Get in the habit of using standard Java naming conventions!
- 07-29-2011, 08:50 PM #3
Using type-import-on-demand declarations (aka star imports) can also cause a maintenance headache. Consider a contrived example:
A maintenance programmer may note the star import of java.util and try to add a List declaration assuming the compiler will treat it as java.util.List -- which it won't, because a single-type-import declaration shadows a type-import-on-demand declaration.Java Code:import java.util.*; // various other imports import java.awt.List; // still more imports
Java Language Specification -- Packages
db
- 07-29-2011, 08:56 PM #4
Not if you used only one of the two identically named classes. And if you do need to use both, you can't escape using the FQN for at least one (but I would use the FQN for both for future readability). Continuing from the last post, this is legal and unambiguously determines that an unqualified List is a java.awt.List. Note that I don't recommend the approach, just sayin'
dbJava Code:import java.util.*; import java.awt.*; import java.awt.List;


3Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks