aspose file tools*
The moose likes Java in General and the fly likes Nested Interfaces? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Nested Interfaces?" Watch "Nested Interfaces?" New topic
Author

Nested Interfaces?

Nick Howell
Greenhorn

Joined: Mar 28, 2002
Posts: 26
Hi, I need to implement an interface that I made inside a nested class:
public class aClass {
class aNestedClass implements anInterface {
}
}
I can apply an interface to a public class by making the public interface and compiling into a package and then importing the package but it won't allow me to apply it to the innerclass. Is there someway I can implement an interface in an innerclass?
Thanks.


Thanks.<br />-Nick
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I don't have any problem compiling this code. How have you defined anInterface? What error message do you get? Are you using an older JDK?


"I'm not back." - Bill Harding, Twister
Nick Howell
Greenhorn

Joined: Mar 28, 2002
Posts: 26
well what my problem is, is that I can compile the interface as public in it's own .java file and put it in a package. I can import this package into my code and implement the interface into a public class but not a non-public class. The reason is that the class's scope must match that of the interface. So what i need is an interface with a scope that isn't public so i can apply it to an inner class.
Thanks.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Nick Howell:
I can import this package into my code and implement the interface into a public class but not a non-public class. The reason is that the class's scope must match that of the interface.

Huh? I never heard of this. Can you please post example code that doesn't compile?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Nick Howell
Greenhorn

Joined: Mar 28, 2002
Posts: 26
aMethod in aPublicClass.aClass.aClass cannot implement aMethod in package.anInterface; attempting to assign weaker access privleges; was public
class aClass implements anInterface {
^
Nick Howell
Greenhorn

Joined: Mar 28, 2002
Posts: 26
the preceeding post was the error message i received by the way.
Thanks!
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Well, make the new method public. You haven't shown any methods at all in the example so far, so it's hard for us to guess what you're talking about.
Nick Howell
Greenhorn

Joined: Mar 28, 2002
Posts: 26
that worked! I misinterpreted the requirement, it's not the class that has to be the same scope as the interface but rather the methods in the interface! I changed all the instantiated methods to public. thank you for your patience.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Nested Interfaces?
 
Similar Threads
access modifiers for Members in an interface
inner class
Nested Classes
Inner Classes - Why can't i access a protected inner class' constructor in a subclass?
Nested Interfaces