Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Why member interface is always static?

Thread view: 
v4vijayakumar@yahoo.com - 13 Apr 2006 10:07 GMT
Why member interface is always static?
Thomas Hawtin - 13 Apr 2006 09:30 GMT
> Why member interface is always static?

Interfaces have no variables. Therefore they cannot have an outer this.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/

Roedy Green - 13 Apr 2006 21:32 GMT
On Thu, 13 Apr 2006 09:30:24 +0100, Thomas Hawtin
<usenet@tackline.plus.com> wrote, quoted or indirectly quoted someone
who said :

>Interfaces have no variables. Therefore they cannot have an outer this.

They have instance implementing methods which might refer to this.

How did you interpret his question?  You can't apply the word static
to an interface. Was he asking why all the members in an interface are
static finals?

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.

EJP - 14 Apr 2006 05:50 GMT
> How did you interpret his question?  You can't apply the word static
> to an interface. Was he asking why all the members in an interface are
> static finals?

class MyClass
{
  interface MyInterface1 {}
  static interface MyInterface2 {}
}

The word 'static' is redundant; both interfaces are static.
v4vijayakumar - 16 Apr 2006 10:47 GMT
> You can't apply the word static to an interface.

agree, but wonder this works with java.

[root@cp_node1 (StkBarolo) java]#cat test.java
public class test {
 static interface vijay {
 }

 public static void main(java.lang.String [] args) {
 }
}
[root@cp_node1 (StkBarolo) java]#javap test$vijay
Compiled from test.java
public class test extends java.lang.Object {
   public test();
   public static void main(java.lang.String[]);
   static interface test. vijay
   /* ACC_SUPER bit NOT set */
{
   }
}
Chris Uppal - 18 Apr 2006 09:18 GMT
> public class test {
>   static interface vijay {
[quoted text clipped - 13 lines]
>     }
> }

When I run this javap doesn't complain about the ACC_SUPER bit, but I wouldn't
worry if it did.

The ACC_SUPER bit is a flag that indicates to the JVM that it should use the
"modern" interpretation of the bytecodes corresponding to code like
   super.doSomething()
(see the JVM spec if you are interested in the details).  That flag is supposed
to be set in every class generated by recent compilers (in fact, since at least
1.0.4), so I presume that's why javap complains when it finds it missing.

However, there is no reason to bother one way of the other about interfaces,
since they don't have real methods, and so can't have code with super-sends.
It seems that the 1.4.2 and 1.5 javacs (at least) don't bother to set the
ACC_SUPER flag for interfaces, whether they are nested or not.  (I can't
imagine why not -- seems pointless to treat them specially)

So it really doesn't matter.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.