• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Nested Interfaces?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Nick Howell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
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 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?
 
Nick Howell
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the preceeding post was the error message i received by the way.
Thanks!
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic