• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Interfaces

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All:
I am just trying to implement this statement in JLS


If the keyword this (�15.8.3) or the keyword super (15.11.2, 15.12) occurs in an initialization expression for a field of an interface, then unless the occurrence is within the body of an anonymous class (�15.9.5), a compile-time error occurs.


and my question is, can a anonymous class have a interface declarations and we can have a usage of 'this' and 'super' keywords.
If it doesn't make any sense, don't bother replying.
 
Ranch Hand
Posts: 178
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arsho, the embodiment of one class having an anonymous inner class means that,
from inside the declaration of the "anonymous" inner class you are free to use the keywords
this and super.

Remember, that implementing an interface within a class means a "is a"
relationship. That means (in our case) the interface "is a" anonymous inner
class... they are one in the same!

So, using the this operator will result in accessing the class members, and
using super will result in accessing the parent's class members.

NOTE: all classes are implicitly subclasses of class Object, so the anonymous
inner class will have a superclass.
--
Rajinder Yadav
[ January 21, 2002: Message edited by: Rajinder Yadav ]
 
Arsho, Ayan
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good !! now Rajinder can u suffice the above with an example.
I tried and it blew up...
-Thanks
 
Ranch Hand
Posts: 5399
1
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

HTH
[ January 21, 2002: Message edited by: ravish kumar ]
 
Ranch Hand
Posts: 172
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I want to be sure that this will not compile because the nested interface is implicitly static therefore cant utilize this or super, correct me if Im wrong plz.
 
reply
    Bookmark Topic Watch Topic
  • New Topic