• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

How to Access a class from a class with inner and local class with same names?

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After doing a search in the forum, I couldn't find an answer for my question. If you see the code below, I would like to access the F class with the message: "Top level class"class. I want to use default package, is there any way to get access to the top level class F?
I don't think there is a one if using default package, but I'm not sure...

 
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose you can access the outer F class like this


Well in your code, the Test1 has an implementation and also the main method. So the code uses the class which is nearest for new F().
 
Ranch Hand
Posts: 196
Android Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as Nitish said,
if there is a name clash just explicitly specify the outer class or interface in which your property lies............
 
armando fonseca
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey guys, i'm trying to find a way using default package or in other words, not using a package name space.
 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

armando fonseca wrote:hey guys, i'm trying to find a way using default package or in other words, not using a package name space.


I don't see a way to do this. The F class inside the main() method shadows the outer F class. And if i am right, the same way as you cannot reach the shadowed variables, you cannot reach the shadowed class...
 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
possible if you found out the name for the default package
 
Anastasia Sirotenko
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitish Bangera wrote: possible if you found out the name for the default package


there is no way for that 8]
Default package has no name and cannot be reffered in any way

Java in a Nutshell By David Flanagan wrote: If no package directive appears in a Java file, all classes defined in that file are part of an unnamed default package. In this case, the qualified and unqualified names of a class are the same. The possibility of naming conflicts means that you should use this default package only for very simple code or early on in the development process of a larger project.

 
Nitish Bangera
Ranch Hand
Posts: 537
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's what i meant. It could have only been possible if there was a name for the default package.
 
Anastasia Sirotenko
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nitish Bangera wrote:That's what i meant. It could have only been possible if there was a name for the default package.


ah, i got no sence of humor left after full day work, time to go home relax
 
armando fonseca
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anastasia Sirotenko wrote:

armando fonseca wrote:hey guys, i'm trying to find a way using default package or in other words, not using a package name space.


I don't see a way to do this. The F class inside the main() method shadows the outer F class. And if i am right, the same way as you cannot reach the shadowed variables, you cannot reach the shadowed class...



I totally agree with you, I don't think there is a way of it, but I'm not 100% certain.
BTW, I forgot to disclaim the the code that I posted is mine... just in case a rancher asked me where I got it.

Armando.
reply
    Bookmark Topic Watch Topic
  • New Topic