• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

why is defult package use discouraged in eclipse

 
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to easy my curiosity I was wondering if anyone knew why is defult package use discouraged in eclipse.
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually, the default package is discouraged everywhere.

Seriously, since the fully-qualified name of a class includes the package name, and the default package (by definition) has no package name, there's too much chance for confusion.

Take an extreme case. Create a class named "String" and place it in the default package. Now define another class in the default package and construct String objects. that is "String xyzzy = new String();"

Can you keep the difference between default "String" and implicit "java.lang.String" straight? Would you like to try on any non-trivial project? Eclipse doesn't.
 
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nikos,
Also, if you have two "default packages" (two unnamed packages in different folders), it's confusing. You can't legally import one from the other as you can only import a package name or fully qualified class. In Java 1.4, Sun explicitly prevented the compiler from accepting this.
 
Nikos Stavros
Ranch Hand
Posts: 243
Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tim and Jeanne for your imformative help. keep up the good work
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
Nikos,
Also, if you have two "default packages" (two unnamed packages in different folders), it's confusing.



In fact it would be the same package, with its content spread over several folders.
 
Jeanne Boyarsky
author & internet detective
Posts: 42003
911
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:


In fact it would be the same package, with its content spread over several folders.


Right. Thanks for wording this in a clearer fashion.
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic