为什么有人会使用Java Thread no arguments构造函数? [英] Why would anyone ever use the Java Thread no argument constructor?

查看:48
本文介绍了为什么有人会使用Java Thread no arguments构造函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在什么情况下,有人会使用Java Thread类的无参数构造函数?API说:

In what situation would anyone ever use the no-argument constructor of the Java Thread class? The API says:

此构造函数与Thread(null,null,gname)具有相同的作用,其中gname是新生成的名称.

This constructor has the same effect as Thread(null, null, gname), where gname is a newly generated name.

如果我错了,请更正我,但是我认为在实例化新的Thread对象后无法修改线程的目标.如果目标等于null,那么start方法将什么都不做?

Correct me if I am wrong, but I think the target of the thread can not be modified after the new Thread object is instantiated. If the target equals null then the start method will do nothing right?

为什么要使用此构造函数?

Why would you use this constructor?

推荐答案

一方面,它允许您创建子类,而无需PITA显式调用超类构造函数.

For one thing, it allows you to create subclasses without the PITA of explicitly calling the superclass constructor, e.g.

new Thread(){ 
   public void run() { ... }
}.start();

这篇关于为什么有人会使用Java Thread no arguments构造函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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