当前位置:网站首页>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
边栏推荐
- Use PHP to delete the specified text content in the file
- Go sync. WaitGroup
- Four isolation levels of MySQL
- JS array sorting method summary
- jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections
- DB2 SQL Error: SQLCODE=-206, SQLSTATE=42703
- For loop and promise to solve the problem of concurrent callback
- Pit used by go language array type
- MFQE 2.0: A New Approach for Multi-FrameQuality Enhancement on Compressed Video
- The difference between settimeout() and setinterval()
猜你喜欢

Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~

Solve the error in my QT_ thread_ global_ End(): 3 threads didn't exit

Learn about data kinship JSON format design from sqlflow JSON format

Mysql database foundation: stored procedures and functions

V3 03_ Getting started
![[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?
![[buuctf] [geek challenge 2019] secret file](/img/00/23bebd013eb4035555c0057725e3c4.jpg)
[buuctf] [geek challenge 2019] secret file

Flat shading with unity

PS cutting height 1px, Y-axis tiling background image problem

Shell programming overview
随机推荐
Tencent two sides: @bean and @component are used on the same class. What happens?
JS delete the objects in the array and specify to delete the objects
Summary of use of laravel DCAT admin
Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
Go sync. WaitGroup
V3 02——What‘s new in Chrome extensions
Uniapp upload image method
Flat shading with unity
Getting started with shell Basics
Upgrade composer self update
數據恢複軟件EasyRecovery15下載
PHP recursive multi-level classification, infinite classification
V3 01_ Welcome
Mysql database foundation: stored procedures and functions
@component使用案例
Alipay certificate mode payment interface
MV3 04_ Introducing Manifest V3
Race of golang
Laravel upload error
Jetpack compose for perfect screen fit