What is the difference between long and long in Android code?

I tried to write AsycTask in an android app. There I came up with integer and long data types, and I'm not sure what it is. I tried using long in place of long , but I got an error in eclipse saying

 'Syntax error on token "long", Dimensions expected after this token'. 
+6
source share
7 answers

Long class. long primitive. This means that Long can be null, and long long can not. Long can go anywhere that takes an Object, long can not (since this is not a class that it does not derive from Object).

Java usually translates long to long automatically (and vice versa), but will not be for null (since long cannot be null), and you need to use the long version when you need to go through a class (e.g. in a generic declaration).

+19
source

Q: What is the difference between β€œlong” and β€œlong”?

A: The first is "primitive"; the latter is an β€œobject”.

Here's a great article suggesting why you might prefer "Long" ("object wrapper"):

Primitive types are considered malicious

PS:

There are many advantages to using a wrapper for Long objects (including null values) and many advantages to using a long primitive (including brevity and efficiency).

Boxing and Unboxing are a mechanism for changing between one and the other. Another good link:

Using boxing with care

+6
source

Integer and long are object wrappers for int and long primitive types.

AsyncTask uses generics to determine values, but generics only accepts objects as parameters.

+1
source

AsyncTask uses common parameters that require parameters of a reference type. long is a primitive type, therefore not allowed. long , on the other hand, is a class, so it should be used.

0
source

long is a primitive data type, and Long is an object.
AsyncTask can only accept parameter objects.

0
source

The long shape of the object is long ...

You should use long and int, unless you need to use methods inherited from Object, such as hashcode. Typically, java.util.collections methods use boxed (Object-wrapped) versions, since they should work for any object

long is also a missing value, while Long is a value passed by reference, like all non-primitive Java types

In addition, Long may be null

0
source

You also need to know the space that they take.

Long inherits from another class, and also contains other values ​​inside:

 public final class Long extends Number implements Comparable<Long> { @Native public static final long MIN_VALUE = 0x8000000000000000L; @Native public static final long MAX_VALUE = 0x7fffffffffffffffL; } 

Long is just one primitive that takes up 8 bytes of space.

This can become very relevant when you are dealing with a lot of data stored in memory or sent over the network.

0
source

Source: https://habr.com/ru/post/945711/


All Articles