This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing a class of default package  RSS feed

 
Vrushali Gore
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working with 3 file in AWT program. I am having directory structure like this :
1. GUI class belongs to package p1
2. Handler class part of default package
3. Invokation even belongs to default package
In this case when I need a Handler class in GUI package p1 it is complaining. As it is a part of default package and GUI is part if Package p1, so from p1 I want to have access over Handler which is not coming out possible.

But if both are part of same package then it is working out. Or even they belong to varoius packages even then there is no problem. Can we have somehow access over classes of default package.

If anyone can help me out I would be very thankful.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, you really can't. Older Java compilers would allow something like

import ClassInDefaultPackage;

but recent versions prohibit this; technically it's always been illegal according to the Java language spec. The lesson: don't use the default package.

If you really, really need to do this, because the default-package classes are third-party classes and you don't have the source, then you could use Class.forName() and reflection. This is a lotta work, but a man's gotta do what a man's gotta do. Otherwise, just fix the classes.
 
Vrushali Gore
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for urgent reply to my query.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!