• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

Inner classes

 
Ranch Hand
Posts: 47
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[size=18][size=12]hello there,

how to invoke methods in an Anonymous inner classes..
[/size][/size]

please anyone help me out here please. i want to invoke the mee() method in the anonymous inner class.
i know that we cant invoke the mee() method with MainClass reference. but i just wanna know how to invoke the methods in the anonymous inner class which are not in the mainclass.




thanks in advance guys
cheers
 
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is possible to invoke anonymous inner class's methods when you try to invoke them on the same line of
declaration ...


I believe there is no other way because anonymous inner classes do not have any name (so casting can not be done) and also
they are implicitly final..
 
author
Posts: 23928
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chaitanya Kidambi wrote:please anyone help me out here please. i want to invoke the mee() method in the anonymous inner class.
i know that we cant invoke the mee() method with MainClass reference. but i just wanna know how to invoke the methods in the anonymous inner class which are not in the mainclass.



Once the class definitions goes out of scope -- and for anonymous classes, that is pretty much by the next line. The only way to call methods that is not defined in an implemented interface or super class (meaning only in the class definition that went out of scope) is to use the reflection API.

Henry
 
Chaitanya Kidambi
Ranch Hand
Posts: 47
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot hardeep. i got it now. but anyway we wont be able to invoke other methods in the anonymous inner class. say for instance , we wont be able to invoke the printmee() method.
am i right ?
 
Hareendra Reddy
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes and we can invoke those methods only by reflection mechanism as Henry said...
 
Chaitanya Kidambi
Ranch Hand
Posts: 47
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a ton guys, both henry and hardeep.
 
Hareendra Reddy
Ranch Hand
Posts: 173
Firefox Browser Fedora Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey ..my name is Hareendra
 
Chaitanya Kidambi
Ranch Hand
Posts: 47
Eclipse IDE Debian Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops sorry mate , my bad.. :p
 
Never trust an airline that limits their passengers to one carry on iguana. Put this tiny ad in your shoe:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic