"Java ee" long.valueof ("" + Requestcontext.globaldata ("Count")); __java

Source: Internet
Author: User
1. Question:
Long.valueof ("" + Requestcontext.globaldata ("Count"));

Why do you need to add "". 2. Answer:

Because, "" is a string, a string plus an object is automatically converted to a string type, and when we debug, if we want to print the object, we should write it carefully:

Object A=new object ();
.../omitted the value given to a to set the individual member variables;

console.log ("Object:" +a)

Because if a is an object, you add a string object to it before you turn it into a string type in debug, and you must look at your needs at this time.
The code in the question can also be written like this:

Long.valueof ((String) requestcontext.globaldata ("Count")

But this is not good, because the type of the strong switch is likely to fail, which is why we have not used (Long) to strongly turn the reason, and then further modified to

Long.valueof (String.valueof (Requestcontext.globaldata ("Count"));

But it is too complicated to write, and the wording of the question is better. Here, if long has a method similar to "", we can convert it in the same way, but I don't know at the moment (not ironic, really not yet), and then the question is, what's the difference between "" and "null"? the difference between 3.null and "";

Why is the difference between "" and null, now the title is changed to null and "" The difference, the reason behind it, sell a word;
The difference is as follows:
①null is empty, nothing, I do not have a house; "Yes, I have a house, but the house is empty; it's a qualitative distinction, The difference is very large;
②string s1=null unassigned address, String s2= "" Assigned address,
③null with equal sign comparison, "" with equals, and first judge is not NULL, and then judge is not "", that is, first judge there is no, Again judge is not empty; here, I feel, null can not be directly translated into "empty", but should be translated into "none", because "" "Chinese name is" empty string ", so that the name will be ambiguous, so that beginners misunderstood, and even a lot of veteran overturned; if (null==s1| | (""). Equals. (S2)), otherwise it will report null pointer exception error; here null to write = = The front, s1 to write = = behind, this is a specification, but also to avoid error tips;

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.