当前位置:网站首页>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
边栏推荐
- [kubernetes series] k8s set mysql8 case insensitive
- JS time conversion standard format, timestamp conversion standard format
- Lifting scanning tool
- [buuctf] [actf2020 freshman competition]exec1
- Begin End use the pit encountered
- [geek challenge 2019] PHP problem solving record
- V3 03_ Getting started
- Ctfshow getting started with the web (ThinkPHP topic)
- Not satisfied with markdown native code block style? Try this beautify code screenshot tool~~
- After the MySQL service on the local computer is started and stopped, some services will automatically stop when they are not used by other services or programs
猜你喜欢

Heavyweight: the domestic ide was released, developed by Alibaba, and is completely open source!

The programming competition is coming! B station surrounding, senior members and other good gifts to you!

Lifting scanning tool

ThinkPHP v3.2 comment annotation injection write shell

Wuenda 2022 machine learning special course evaluation is coming!

Shell programming overview

Deep understanding Net (2) kernel mode 2 Kernel mode construct semaphone

Laravel upload error

Detailed explanation of the first three passes of upload Labs

【BUUCTF】 EasySql
随机推荐
An error is reported when installing dataspherestudio doc: invalid default value for 'update_ time‘
Four isolation levels of MySQL
Computer screenshot how to cut the mouse in
Experiment 2: stack
【BUUCTF】 EasySql
Introduction to the renewal of substrate source code: the pallet alliance is incorporated into the main line,
KnightCTF WEB
remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac
Solve the error in my QT_ thread_ global_ End(): 3 threads didn't exit
XSS challenge (1-5) more detailed answers
Geoffreyhinton: my 50 years of in-depth study and Research on mental skills
Thinkphp5 log file contains trick
JS array sorting method summary
MySQL back to table query optimization
Summary of use of laravel DCAT admin
Pytoch viewing model parameter quantity and calculation quantity
V3_ Chrome extended Chinese translation document V3 directory
XSS challenge (6-10) more detailed answers
Lost connection to the flow server (0 retries remaining): |Out of retries, exiting! Error reporting solution (flow)
Chapter 13 signal (III) - example demonstration