jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes code explanation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "code explanation" Watch "code explanation" New topic
Author

code explanation

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Anyone please expalin the code below,what this code says

class h {

Fa fa = new Fa() {

public Object make() {
return new js();
}
};

}
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

It doesn't look like it compiles.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Where did you get that from? It is full of all sorts of stylistic unconventialities. If you are copying from books or website, please Quote Your Sources.

You need to have a class js with a no-arguments constructor, and a class Fa, then it is actually very similar to this thread. It is an anonymous subclass of Fa with a make() method.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

If you say "stylistic unconventialities" again I may need to pay someone to smack you
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Can I choose who it is? As long as it isn't Rob.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38519
    
  23
Originally posted by David O'Meara:
Oh, no. That means you will do it!

Shall we get back to the official subject of this thread?
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Dear all

I do not want to know whether it will complie or not.It is part of successful code,I just want explanation,you all think that it is a pseudo code.
[ October 13, 2008: Message edited by: jacob deiter ]
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
The answer has been given.

It is creating in instance of a subclass of Fa that is anonymous (it has no name). The subclass contains one method that has been customized.


Standard:


Anonymous Subclass:


you normally don't see this in hand-coded Java,
but you often see it in machine-generated Java code,
[ October 13, 2008: Message edited by: Bill Shirley ]

Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Thank you Bill
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19685
    
  20

Originally posted by Campbell Ritchie:
Can I choose who it is? As long as it isn't Rob.

If the question was about who was going to kick you, you'd beg for me to do it. I still have just a little power in my kicking leg

Originally posted by Bill Shirley:
you normally don't see this in hand-coded Java,

Then you haven't seen my code. Especially in user interface programming I do it all the time:

And yes, I code 90% of my code by hand. The only code I let Eclipse generate for me is getters and setters, and even those I tweak to get at least the Javadocs correct. "Sets the myField"... ARGH!


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code explanation