• 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

How to access this interface?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
can anyone tell me how to access the inner interface (bar)...?

When i compile both i got an error:
TestFoo.java:6: cannot resolve symbol
symbol : variable MY_CONST
location: class java.lang.String
System.out.println("Const= " + foo.bar.MY_CONST);
^
1 error
So how can i access the inner interface???
Thanks in advance and regards
Dirk
(edited by Cindy to format code using [ code] and [ /code] tags without the spaces)
[ August 28, 2003: Message edited by: Cindy Glass ]
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Something (like an inner class) would need to implement the interface first. Then you can get at it through an object of that inner class.
 
Dirk Lehmann
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cindy,
thanks for your quick reply.
What wonders me is that, if i comment the line
public static final String bar = "Class const";
out, it works fine. I can access the interfaces constant without
implementing the interface....
Regards
Dirk
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If this is a party trick, you could write

i.e., use an empty, anonymous implementation. Otherwise, if this came up in a real program, I think the solution is that you're going to have to rename something. Even if there was a non-obvious way to access the interface constant directly, do you really want to write code that requires alien super-genius to interpret? I think it was Steve Maguire in "Writing Solid Code" who said that if you ever find yourself writing code and you say to yourself 'Wow, I'm clever!', immediately delete the code and rewrite it in a more straightforward way. The maintenence programmer who comes after you isn't going to be as impressed by your code as you are.
 
Drove my Chevy to the levee but the levee was dry. A wrung this tiny ad and it was still dry.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic