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