1. Find the followingCodeError
Public class test {
Public test (){
}
Test;
{
A = new test ();
}
Static Test S;
Static {
S = new test ();
}
Public static void main (string [] ARGs ){
New Test ();
}
}
Error: When the instance variable is initialized, its attribute is its own class, so it will keep repeating there during creation.
Error principle: the static variable instance is shared in the memory once. Instance variables are divided into memory space each time, and instances are created each time.
2. Java Enumeration
Package test. Test2;
Public Enum trice {
Red (1 ){
Public trice getnext (){
Try {
Thread. Sleep (Super. A * 1000 );
System. Out. println ("the thread sleep" + super. );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
Return green. getnext ();
}
},
Green (2)
{
Public trice getnext (){
Try {
Thread. Sleep (Super. A * 1000 );
System. Out. println ("the thread sleep" + super. );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
Return yellow. getnext ();
}
}, Yellow (3)
{
Public trice getnext (){
Try {
Thread. Sleep (Super. A * 1000 );
System. Out. println ("the thread sleep" + super. );
} Catch (interruptedexception e ){
E. printstacktrace ();
}
Return red. getnext ();
}
};
Public int;
Private trice (int ){
This. A =;
}
Public abstract trice getnext ();
}
Java enumeration variables inherit the outer enumeration class by default, so the implementation of the parent class Method
3. The fastest way to clear duplicate list items: Use hashset