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

What is the assignment method of java long type data?

WBOY
WBOYforward
2023-04-28 15:52:061808browse

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;

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;

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();

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!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete