当前位置:网站首页>2021-08-07 native and package types
2021-08-07 native and package types
2022-06-30 14:33:00 【tutou_ girl】
Writing Java In the process of code , Has been to Java Some of the class parameters provided are questionable , I checked it today , Learn to understand .
type argument cannot be of primitive type
problem :
- Java What are native types in ?
- Java What is the encapsulation type in ?
Java Primitive types and primitive encapsulation types in
Java There are two different types : Reference types and primitive types ( Or built-in type ). such as :Int yes java Original data type of ,Integer yes java by int Provided encapsulation class .Java A wrapper class is provided for each primitive type , Common primitive and corresponding encapsulation classes are as follows :
The original type Wrapper class
boolean Boolean
char Character
byte Byte
short Short
int Integer
long Long
float Float
double Double
The difference between the reference type and the original type :
1. The initialization methods are different
int i = 5; // The original type
Integer j = new Integer(10); // Object reference java 1.5 In the future, it supports automatic packing, so Integer j = 10; It's fine too
Using primitive types does not require calling new, There is no need to create objects . This saves time and space . Mixing primitive types and objects can also lead to unexpected results related to assignment .
2. Original type is class , Reference types are objects
The original type size is compared with "==" , The reference type size is compared with "equals"
3. Reference types can be serialized , The original type cannot .
4. The methods provided by reference types can be flexibly converted , You can extend the , The original type cannot
5. Only reference types can be used in collection classes , Cannot use primitive type
6. Original type has no null The concept of , There are , In some cases, it is necessary to identify whether a parameter has been initialized , If you use the original type , that 0 I don't know whether it is the initial value or not. The system automatically gives it .
7. Sometimes you have to use encapsulated classes , For example, if you want to use
request.setAttribute(String key ,Object value); This method , The second parameter is Object type , When you want to put an integer , Then you can only put Integer Can't put int.
summary :
The behavior of primitive and encapsulated types is completely different , And they have different semantics . Reference types and primitive types have different characteristics and usages , They include : Size and speed issues , What kind of data structure does this type store , The default value specified when the reference type and the original type are used as instance data for a class . The default value of the object reference instance variable is null, The default values of primitive type instance variables are related to their types .
int( The original type ) Generally, it is enough to be a numerical parameter
integer ( Package type ) It is generally used for type conversion
边栏推荐
- [scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)
- For loop and promise to solve the problem of concurrent callback
- The first three passes of sqli Labs
- Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!
- LIS error: this configuration section cannot be used in this path
- Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
- @Role of ResponseBody
- NoViableAltException([email protected][])
- Project management - common English vocabulary I
- Error on datetime when importing SQL file from MySQL
猜你喜欢

Tencent two sides: @bean and @component are used on the same class. What happens?

ctfshow nodejs
![[geek challenge 2019] PHP problem solving record](/img/bf/038082e8ee1c91eaf6e35add39f760.jpg)
[geek challenge 2019] PHP problem solving record

2021 geek challenge Web
![[observation] as the intelligent industry accelerates, why should AI computing power take the lead?](/img/61/b446a616e86247507c27390505dc6b.jpg)
[observation] as the intelligent industry accelerates, why should AI computing power take the lead?

Attack and defense world web questions

LIS error: this configuration section cannot be used in this path

Error on datetime when importing SQL file from MySQL

Initial attack and defense world Misc

QQ was stolen? The reason is
随机推荐
[geek challenge 2019] PHP problem solving record
Go language for loop multivariable use
Learn about data kinship JSON format design from sqlflow JSON format
go channel && select
PS cutting height 1px, Y-axis tiling background image problem
數據恢複軟件EasyRecovery15下載
JMeter transaction controller
Wuenda 2022 machine learning special course evaluation is coming!
JS delete the objects in the array and specify to delete the objects
Laravel upload error
@ResponseBody的作用
@Component use cases
Tencent two sides: @bean and @component are used on the same class. What happens?
Implement a long-click list pop-up box on apiccloud
How to execute a query SQL
Chapter 13 signal (III) - example demonstration
Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!
[buuctf] [actf2020 freshman competition]exec1
jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections
An error is reported when installing dataspherestudio doc: invalid default value for 'update_ time‘