Home > Java > javaTutorial > What is the assignment method of java long type data?

What is the assignment method of java long type data?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2023-04-28 15:52:06
forward
1933 people have browsed it

Assignment of java long type data

Problem

When a large value appears in the program (exceeding the int type: -2^31 to 2^31 - 1), The type needs to be changed to Long type.

long l = 1507772738542;
Long l1 = (long)1507772738542;
Copy after login

The above writing method will report an error during compilation.

What is the assignment method of java long type data?

It probably means that the data is too long and exceeds the value of type int.

Solution

Long l = 1507772738542L;
Copy after login

You can add L or l after the data.

The strange problem caused by assigning null to long

The reason for the problem

I get a Long type data from an object and assign it to a long variable:

long startsecond =  tracelist.get(i).getTracesecond();
Copy after login

Because Tracesecond must have a value when acquiring data before, so the null data was not judged. However, later it was found that the attribute of data was null. When executing the code, the code will get stuck in this place and will never be executed. Go down.

Writing a test example alone, I found that a null pointer exception was reported. I don’t know if it was caused by my code in the thread.

The above is the detailed content of What is the assignment method of java long type data?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Install JAVA
From 1970-01-01 08:00:00
0
0
0
Unable to install java
From 1970-01-01 08:00:00
0
0
0
Can java be used as the backend of the web?
From 1970-01-01 08:00:00
0
0
0
Is this in Java language?
From 1970-01-01 08:00:00
0
0
0
Help: JAVA encrypted data PHP decryption
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template