Each language has its own callback method, and Java is no exception.
Java callback uses a multi-state method to call back and forth. For example:
Interface mouselistener {// when the click method is called, it indicates that the mouse has clicked. Void click ();}
The above is an interface with only one method in it. First, we will use an example to show that Java is used to display the power of polymorphism.
Public class model {// initialize 50 listeners private mouselistener [] listeners = new mouselistener [50]; // used to record where the current listeners Array records int Index = 0; public void addlistener (mouselistener listener) {// register a listener listeners [index ++] = listener to this model;} public void clickmodel () {// call the click Method for registering all listener for (INT I = 0; I <index; I ++) {listeners [I]. click () ;}/// test model public static void main (string [] ARGs) {model = new model (); // Add an anonymous internal class, the click method is implemented. model. addlistener (New mouselistener () {public void click () {system. out. println ("I was clicked") ;}}); // Add another internal class. model. addlistener (New mouselistener () {public void click () {system. out. println ("I was clicked") ;}}); // click model below. clickmodel ();}}
Ii. java. Lang. outofmemoryerror: Java heap Space
Solution in myeclipse:
Myeclipse-> preferences-> myeclipse-> servers-> tomcat-> Tomcat ×. ×-> In the JDK panel
Added in optional Java VM arguments
-Xmx512m-xms256m-XX: maxpermsize = 256 m