Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use for nested interfaces

 
Bill Nelsen
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started to play around with nested interfaces, because I read that by definition they are static. So this is the trivial example that I arrived at,

interface A {
interface B {
void help();
}
}
class Base implements A.B {
public void help() { System.out.println("Help"); }
}

class Test {
static public void main(String[] args) {
A.B b = new Base();
b.help();
}
}

Since the nested interface is static, it requires this unusual notation (or at least I think that it does). I have a difficult time intuitively picturing what a static interface would look like. Is there a good use for a nested interface or is it just a feature (like interfaces that contain concrete classes), which is just there for completeness, but doesn't really serve a useful purpose??
~
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nested interfaces also means interfaces defined within a class. In this article an example of such nested interfaces is given.
 
Bill Nelsen
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the link to a great article. I am reading all 3 parts of the article.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic