当前位置:网站首页>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
边栏推荐
- Vue returns to the previous page without refreshing the page / Vue caches the page
- Laravel upload error
- Thoughts on the security of a PHP file name regular verification
- For loop and promise to solve the problem of concurrent callback
- Att & CK red team evaluation field (I)
- 【BUUCTF】 EasySql
- NoViableAltException([email protected][])
- About the problems encountered when using the timer class to stop with a button (why does the QPushButton (for the first time) need to be clicked twice to respond?)
- Why does the folder appear open in another program
- Details of gets, fgetc, fgets, Getc, getchar, putc, fputc, putchar, puts, fputs functions
猜你喜欢
The first three passes of sqli Labs
PS cutting height 1px, Y-axis tiling background image problem
What network security problems are exposed when a large-scale QQ number theft event occurs?
Problems in QT creator (additional unknown and error lines are listed in the debug output window)
JS to realize simple lottery function
Why does the folder appear open in another program
Laravel configures passport and returns token using JWT
Tencent two sides: @bean and @component are used on the same class. What happens?
Lifting scanning tool
Attack and defense world web questions
随机推荐
Cost forecast of PMP (BAC, EAC, etc)
V3 02——What‘s new in Chrome extensions
PHP multidimensional array sorting
【BUUCTF】[GXYCTF2019]Ping Ping Ping1
[scientific research data processing] [practice] frequency analysis chart of category variables, distribution chart of numerical variables and normality test (including lognormal)
JMeter transaction controller
Deep understanding Net (2) kernel mode 3 Kernel mode construct mutex
Getting started with shell Basics
V3_ Chrome extended Chinese translation document V3 directory
Shell programming overview
For loop and promise to solve the problem of concurrent callback
remote: Support for password authentication was removed on August 13, 2021. Please use a personal ac
PHP 2D array change key name
數據恢複軟件EasyRecovery15下載
Introduction to the construction and development of composer private warehouse
Go language for loop multivariable use
@Component use cases
Chapter 13 signal (III) - example demonstration
jsPlumb. Deleteeveryconnection is not a function & jsplumb clear canvas jsplumb delete all nodes and all connections
The first dark spring cup dnuictf