Summary of $1. Class and $2. class after compilation

Source: Internet
Author: User

This is because there is an anonymous class in the class we write.
1:
APIs and abstract classes cannot be instantiated.
See the following code.
Actionlistener listener = new actionlistener ()
{
Public void actionreceivmed (actionevent EVT)
{
// Do action
}
};
What is the listener class object? The interface cannot be instantiated.
The class name is called an anonymous class.
After a class file is compiled, many class names contain the $ character, such as testframe. Class, testframe $1. Class, testframe $2. Class, testframe $ myjob. Class.
$ The class followed by the number is the result of the anonymous class compilation. testframe $ myjob. Class is obtained after the internal class myjob is compiled.
The use of internal classes can hide some implementation details, and so on. There are other advantages. When using anonymous classes, pay attention to the readability of the Code.
For better understanding, two examples are listed below:
(1): If the findprojectresult method in the class abstractmmitemjdbcdaoimpl appears like new rowmapperresultreader (New rowmapper (), $1 will appear when compiling the class file abstractmmitemjdbcdaoimpl. class, $2. class
Return getjdbctemplate (). Query (SQL, new rowmapperresultreader (New rowmapper (){
Public object maprow (resultset RS, int _ INT) throws sqlexception {

Resultlistpojo = new resultlistpojo ();
Resultlistpojo. setbillcode (Rs. getstring ("billcode "));
Resultlistpojo. setapplybillcode (Rs. getstring ("applybillcode "));
Resultlistpojo. setapplydate (Rs. getstring ("applydate "));
Resultlistpojo. setmmitemid (Rs. getlong ("mmitemid "));
Resultlistpojo. setmmcode (Rs. getstring ("mmcode "));
Resultlistpojo. setmmname (Rs. getstring ("mmname "));

Resultlistpojo. setprojectcode (Rs. getstring ("itemcode "));
Resultlistpojo. setprojectname (Rs. getstring ("itemname "));

Resultlistpojo. setmmfullname (Rs. getstring ("mmname") + (Rs. getstring ("Specification ")! = NULL? Rs. getstring ("Specification "):""));
Resultlistpojo. setbillid (Rs. getlong ("billid "));
Resultlistpojo. setbilltype (Rs. getlong ("billtype "));
Resultlistpojo. setbilltypename (Rs. getstring ("billtypename "));
Resultlistpojo. setengineername (Rs. getstring ("engineername "));
Resultlistpojo. setprice (Rs. getdouble ("price "));
Resultlistpojo. setunitname (Rs. getstring ("unitname "));
Resultlistpojo. setstorename (Rs. getstring ("storename "));
Resultlistpojo. setwoflagname (Rs. getstring ("woflagname "));

Resultlistpojo. setplanamount (Rs. getdouble ("planamount "));
Resultlistpojo. setstoreamount (Rs. getdouble ("storeamount "));
Resultlistpojo. setplansummoney (Rs. getdouble ("price"), RS. getdouble ("planamount "));
Resultlistpojo. setstoresummoney (Rs. getdouble ("price"), RS. getdouble ("storeamount "));

Resultlistpojo. setapplymanstandardweight (Rs. getdouble ("applymanstandardweight "));
Resultlistpojo. setdispatcherstandardweight (Rs. getdouble ("dispatcherstandardweight "));
Resultlistpojo. setdispatcheractualweight (Rs. getdouble ("dispatcheractualweight "));
Resultlistpojo. setstoremanactualweight (Rs. getdouble ("storemanactualweight "));

Resultlistpojo. setinorout (Rs. getint ("inorout "));
Return resultlistpojo;
}
}));
(2): Typical use
Most commonly anonymous classes are used to field events in listeners.

// This code goes in your dialog class
// To shutdown the Dialog
// When the user clicks the dismiss button.
Dismissbutton. addactionlistener
(New actionlistener ()
{
/**
* Close down the dialog when user clicks dismiss
*/
Public void actionreceivmed (actionevent event)
{
Object object = event. getsource ();
If (Object = dismissbutton)
{
Dismiss ();
} // End if
} // End actionreceivmed
} // End Anonymous class
); // End addactionlistener line

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.