是第一次调用静态方法时自动创建的类的实例 [英] Is an instance of a class automatically created when you first call a static method

查看:409
本文介绍了是第一次调用静态方法时自动创建的类的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道你是否有一个只有静态方法的类,当你调用第一个静态方法时,是否会在某个地方创建一个类的实际实例?

I would like to know if you have a class with only static methods in it, does an actual instance of the class get created somewhere when you call 1st static method?

在内存管理方面理解这有点令人困惑,因为你从未实际调用构造函数或显式创建方法的实例。

This is somewhat confusing to understand in terms of memory management as you never actually call the constructor or create an instance of the method explicitly.

如果实例创建了,我想更好地了解这个实例的存在时间和持续时间。

If an instance does get created, I would like to better understand where this instance lives and for how long.

推荐答案

不。调用 static 方法不需要(或创建)的实例。另请参见 JLS-8.4.3.2 static 方法,其中(部分)

No. Calling a static method does not require (or create) an instance of a class. See also JLS-8.4.3.2 static methods which says (in part)


一种方法声明 static 被称为类方法。

...


A class始终在不引用特定对象的情况下调用方法。

A class method is always invoked without reference to a particular object.

这篇关于是第一次调用静态方法时自动创建的类的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆