• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

page 12 OCA 8 Guide: no naming conflict with wildcard within the main method ?

 
Greenhorn
Posts: 17
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi there, I was playing with the code on page 12 of the OCA 8 Guide. I've tested in fact the code does not compile for the following code, due to conflicting class in both packages:




My question: However, I then tried the code in the example below, and while it still does not compile if you specify to import the Date class... it does compile with no problems when you import both packages with the wildcard. Why?
Thanks in advance,


--------- import with specific class --------- does not compile


"error: a type with the same simple name is already defined by the single-type-import of Date
import java.sql.Date"


--------- import with wildcard --------- compiles
 
author & internet detective
Posts: 39343
755
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pedro,
Great question! The rule of thumb is that Java needs one of the classes to be fully qualified to know what should be considered most important. In your second example, you try to specify both so Java doesn't know what to do.

The third example, uses Random which is only in one package so doesn't have a conflict anyway.

 
Pedro Esgueira
Greenhorn
Posts: 17
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeanne,

Yes, I understand now. Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!