This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Anonymous Inner Class. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B Anonymous Inner Class." Watch "K&B Anonymous Inner Class." New topic
Author

K&B Anonymous Inner Class.

Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400



SCJP6 96% | SCWCD5 81% | SCDJWS5 79%
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

You cannot access sizzle directly. There might be a way of doing that using reflection, but that's not in SCJP objectives so you don't need to worry...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

I see - thanks ankit. however, can you show me that reflection code to access sizzle?? if its convenient for you?
Amrita Udupa
Greenhorn

Joined: Dec 15, 2009
Posts: 2
Alternatively you could include the sizzle in your popcorn class and then call it in the main method
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Here's a small code that I created to call a method on an anonymous inner class object which is not a part of the super class of the anonymous inner class.


Remember I'm no reflection guru, I just looked at the docs and this article and made this program...
Leonardo Carreira
Ranch Hand

Joined: Apr 07, 2009
Posts: 489

Hi.. what K&B stands for?..
sorry i don't know it abbreviation..

Thanks..


Sorry, perhaps my english language isn't too good.. Prepare for SCJP 6, Please God help me.. ☼
References : [Java.Boot] [JavaChamp] [JavaPrepare]
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

Hi Leonardo Carreira, the people around javaranch use k&B as short term of book Java 6 Study Guide by Katherine Sierra & Bert Bates.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Leonardo Carreira wrote:Hi.. what K&B stands for?..

It refers to SCJP Study Guide by Kathy Sierra and Bert Bates (K&B = Kathy & Bert)...
Minhaj Mehmood
Ranch Hand

Joined: Jan 22, 2007
Posts: 400

Ankit Garg wrote:
Remember I'm no reflection guru, I just looked at the docs and this article and made this program...


Mr.Ankit, it's absolutely fine if you are not guru, i just asked because i was not able to call method "sizzle()" through reflection my self.

Thanks
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9291
    
  17

Minhaj kaimkhani wrote:Mr.Ankit, it's absolutely fine if you are not guru,

Well I said that because I had to make the method local class' method (innerMethod) public otherwise I was getting an exception. But I'm sure that non-public members of a class can be accessed using reflection, I just don't know why it didn't work (and I'm not interested in knowing as of now as I don't have any reason why I should learn reflection inside out )...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B Anonymous Inner Class.
 
Similar Threads
Inner classes
Anonymous inner class
Argument-defined anonymous class call
Anonyms Inner Class ????
Is there a way to invoke new methods defined in Anonymous classes?