Why I must have Map<Long,... and not Map<long, [duplicate] - java

This question already has answers here:
Why don't Java Generics support primitive types?
(5 answers)
Closed 7 years ago.
That's all. I understand that Long is an object, and long is a primitve type, so why can't I map an object to a number?

First of all... Long is not an object, it is a Class.
Now about your question...
In Generics,unlike C#, Java doesn't support primitive type yet.

Related

Java primitive type storage [duplicate]

This question already has answers here:
Java primitive types and objects structure in memory
(4 answers)
Where does the JVM store primitive variables?
(3 answers)
What's the difference between primitive and reference types?
(9 answers)
Closed 1 year ago.
I know primitives variables store values and obj variables store references. But technically is a primitive variable a reference to the location where the primitive value is in memory? B/c you have to know the location of the value.

OOP - What is the proper definition between instance and object? [duplicate]

This question already has answers here:
Difference between object and instance
(15 answers)
The difference between Classes, Objects, and Instances
(16 answers)
What is the difference between object and instance?
(10 answers)
Closed 3 years ago.
Is instance and object same thing in OOP or not?
A good explanation Here. But some explanation is so confusing.
I want to know best explanation. Advance thanks .

Which one is better to work with, vector or arraylist? [duplicate]

This question already has answers here:
Why is Java Vector (and Stack) class considered obsolete or deprecated?
(5 answers)
Closed 3 years ago.
I have to do a program using arrays of objects to make a person type object that receives ID, name, gender ... etc. which is better to use arraylist or vectors?
ArrayList is better (with Collections.synchronizedList if you need a thread-safe list, which I doubt you do). See this question.

What does the symbol <?> mean? [duplicate]

This question already has answers here:
What does the question mark in Java generics' type parameter mean? [duplicate]
(6 answers)
Java syntax <?> explanation
(1 answer)
Closed 7 years ago.
While doing some android app development, I encounter the parameter AdapterView< ? > test. My question is what exactly does < ? > mean or do because I also see it in many other places such as a Map where it is Map< String ,? >.
In generic code, the question mark (?), called the wildcard, represents an unknown type.
The wildcard can be used in a variety of situations: as the type of a parameter, field, or local variable; sometimes as a return type.
So in order to answer the question: it is a Wildcard-> Official Doc so you can handle classes event when you dont know the type.

Primitive vs Object type in Java [duplicate]

This question already has answers here:
Why do people still use primitive types in Java?
(21 answers)
Closed 9 years ago.
This question came to my mind because I have read somewhere that Java is not a pure Object oriented language since it is using primitives (which are not objects). I can agree with that. Now my problem is why we are using primitives/wrappers while we already have Object in same type?
As an example if we consider Integer, It has same value limit as int other than object behavior. why still Java use primitives under these condition?
As my opinion, if Java only use Object type Autoboxing and Unboxing no need. Also there is no primitive for String by the way.
One reason is due to memory usage. Primitives, such as int, float etc. require less memory allocations (I think 4 bytes) in comparison to Objects which are at the very least 8 bytes. Please see the following reference:
In addition, a lot of arithmetic (numeric) is completed with the use of primitives rather than their Object equivalents and this is another reason why they are quite critical in the Java language.

Categories