Java Note 1

Source: Internet
Author: User

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

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.