Android switch cannot use the workaround for class such as parameter String,view

Source: Internet
Author: User

Based on Method: Object.hashcode ();

The principle of hashcode ():

The hash value itself is a hash code, in short, each object corresponds to a hash value (int), so the role of hashcode in a timely and globally unique indicator;

In the same run environment, the hashcode value is unique so that you can distinguish between objects that are physically not the same as the class instance

However, for example

String obj_a= "AAA";

String obj_b= "AAA";

Obj_a,obj_b is the same, because the reason for the Java String Pool optimization is that each declaration of a string, the JVM will first look for a "string pool" to see if there is the same string, if there is an existing object reference returned, rather than a new string object, the same

String obj_a = new String ("BBB");

String obj_b = new String ("BBB");

is also the same hashcode, in general equals the same words, hashcode should be the same

So use

Switch (Object.hashcode ());

It's all right.

Android switch cannot use the workaround for class such as parameter String,view

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.