什么条件导致对象实例化返回null? [英] What conditions cause object instantiation to return null?

查看:199
本文介绍了什么条件导致对象实例化返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下行是否可能返回null?

  MyClass obj = new MyClass 

如果是,什么条件会导致返回值为null?


b
$ b

15.9.4节Java语言规范


类实例创建表达式的值是对新创建的指定类。每次对表达式求值时,都会创建一个新对象。



Is it possible for the following line to return null?

MyClass obj = new MyClass();

If so, what conditions would cause a return value of null?

解决方案

It's impossible for new to return null, assuming the VM is functioning correctly.

From section 15.9.4 of the Java Language Specification:

The value of a class instance creation expression is a reference to the newly created object of the specified class. Every time the expression is evaluated, a fresh object is created.

这篇关于什么条件导致对象实例化返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
Java开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆