File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Using A-D.A.I.C. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Using A-D.A.I.C." Watch "Using A-D.A.I.C." New topic
Author

Using A-D.A.I.C.

Prakalp Shrivastava
Greenhorn

Joined: Aug 03, 2006
Posts: 4
To cut the short story long, can anyone please enlighten me on the practical significance/benefits/scenario where I can imagine using Argument-Defined Anonymous Inner Classes.

Also, as I found this concept can be used with both interfaces and classes with the only 'real big' difference being that while implementing interfaces I would need to define all the abstract methods.

Can someone please tell me that there is more to this than meets the eye(atleast at first glance

Cheers,
PK.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Let see if Java In General (Intermediate) can help. A-D.A.I.C isn't, I believe, a topic of the SCJP objectives.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
I do know what anonymous inner classes are, but what does argument-defined mean?


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Ilja Preuss:
I do know what anonymous inner classes are, but what does argument-defined mean?

You too? Now you know why I dumped it over here
Prakalp Shrivastava
Greenhorn

Joined: Aug 03, 2006
Posts: 4
Originally posted by Barry Gaunt:
Let see if Java In General (Intermediate) can help. A-D.A.I.C isn't, I believe, a topic of the SCJP objectives.


Thanks for moving the thread Barry Hopefully I will get some useful pointers here.

Also, Question related to A-D.A.I.C. have been coming in SCJP exams.
Prakalp Shrivastava
Greenhorn

Joined: Aug 03, 2006
Posts: 4
Originally posted by Ilja Preuss:
I do know what anonymous inner classes are, but what does argument-defined mean?


Hi Ilja,
Thanks for replying

At the most basic level, A-D.A.I.C. are just what the name suggests.
They are anonymous implementation of interfaces, defined in the calling methods argument list.

This, seemingly, allows the method to instantiate and use an interface 'object' for otherwise mundane java tasks

In my understanding, this can additionally be spiced up a bit by having subclasses defined in the method argument list as well. Ofcourse, other rules governing anonymous classes apply to this technique like no more than one interface can be implemented etc.

Now, my real doubt is why/what is the exact use of this knowledge(!!) As I see it, this is just like trying to catch the ear from the wrong side.
Any inputs on this wud be highly appreciated.

Cheers,
PK
[ August 04, 2006: Message edited by: Prakalp Shrivastava ]
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Ah, so the following would be an A-D.A.I.C.



In my experience, ADAICs are most often used as callbacks: http://en.wikipedia.org/wiki/Callback_%28computer_science%29

In fact, as I think about it, most of my AICs are ADAICs...

Does that help?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18991
    
    8

I didn't recognize the term either (and I don't particularly see why the term even needs to exist). But as Ilja says, it's a common way of doing things once you get the idea of anonymous inner classes. For example:
Prakalp Shrivastava
Greenhorn

Joined: Aug 03, 2006
Posts: 4
Danke Ilja for the wiki link
It did clear some ideas in my head regarding callback approach et al. but the concept seems to be more application to C/C++ type languages than any other.

Still doing some more reading on this, and will keep updated if I find something really worth sharing with you all .
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Originally posted by Prakalp Shrivastava:
the concept seems to be more application to C/C++ type languages than any other.


In which way?

It's actually a common technique in quite a lot of different languages: OO languages using Strategies/Commands etc. or inbuild language support such as C# delegates or Smalltalks closures; function pointers in procedural languages; etc. pp.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Using A-D.A.I.C.