当前位置:网站首页>String s = null ; String s = new String();String s =““ ;String s ;有什么区别?
String s = null ; String s = new String();String s =““ ;String s ;有什么区别?
2022-06-12 17:10:00 【积分中值定理】
1.String s =null ;
未申请任何内存资源,只是声明了对象的引用,并没有把对象真正的实例化出来,仅仅是把栈内存的String引用指向了一个null,表示声明了一个引用变量并初始化引用,但是该引用没有指向任何对象.但可以把它作为参数传递或其它使用,但是不能调用它作为对象的方法。
2.String s ="" 和String s = new Stirng();
是真正的把对象创造出来,并把对象放到堆内存里。String s=""; 表示申请了内存资源,但资源空间值为空。该语句表示声明并引用到一个对象,只不过这个对象为0个字节.所以既然有了对象,就可以调用对象的方法。
3.String s ;
该语句表示只是声明了一个引用变量,但是并没有初始化引用,所以对变量s的任何操作(除了初始化赋值外) 都将引发异常。
边栏推荐
- rolabelImg的安装使用
- Tidb Hackathon 2021 - pcloud: conduct icloud pcloud team interview on the database
- Feedback compilation
- (七)循环语句for
- Alibaba cloud image station supports IPv6!
- (四)Golang运算符
- R语言使用epiDisplay包的pyramid函数可视化金字塔图、基于已有的汇总数据(表格数据)可视化金字塔图
- Application case of smart micro 32-bit MCU for server application cooling control
- MySQL事务简介、事务隔离级别
- Cicada mother talks to rainbow couple: 1.3 billion goods a year, from e-commerce beginners to super goods anchor
猜你喜欢

Swintransformer network architecture

Gerrit+2 triggers Jenkins task

Qiushengchang: Practice of oppo commercial data system construction

两位新晋Committer的“升级攻略”

How to change Golan back to the English version when it becomes the Chinese version

Dongfeng Yueda Kia, Tencent advertising and hero League mobile game professional league cooperate to build a new E-sports ecology

Cloud development kunkun chicken music box wechat applet source code

淘宝Native研发模式的演进与思考 | DX研发模式

Installation and use of rolabelimg

Gerrit+2触发Jenkins任务
随机推荐
Selenium element positioning
力扣今日题926. 将字符串翻转到单调递增
C # final review programming question (guessed by the teacher)
I heard that distributed IDS cannot be incremented globally?
R语言使用epiDisplay包的summ函数计算dataframe中指定变量在不同分组变量下的描述性统计汇总信息并可视化有序点图(名称、有效值个数、均值、中位数、标准差、最大值、最小值)
Yyds dry goods inventory leetcode question set 911 - 920
Record the use of yolov5 to detect rotating targets
Crazy temporary products: super low price, big scuffle and new hope
MySQL transaction introduction and transaction isolation level
Concurrent trichromatic marking
Cicada mother talks to rainbow couple: 1.3 billion goods a year, from e-commerce beginners to super goods anchor
Male god goddess voting source code v5.5.21 voting source code
Play kubernetes every 5 minutes summary
如何查看、修改和删除SSH
Gerrit triggers Jenkins sonarqube scan
Alibaba cloud image station supports IPv6!
Add static route
Microsoft Office MSDT代码执行漏洞(CVE-2022-30190)漏洞复现
redis. clients. jedis. exceptions. JedisConnectionException: Could not get a resource from the pool
Analysis of CA certificate with high value