蚀。我可以删除Java类构造函数,使Eclipse自动重构吗? [英] Eclipse. Can I delete a Java class constructor such that Eclipse automatically refactors?

查看:114
本文介绍了蚀。我可以删除Java类构造函数,使Eclipse自动重构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个空的构造函数为一个类。我想删除构造函数,但有很多地方我有这样的东西,如:



Klass my_klass = new Klass();我想删除构造函数并让Eclipse自动重构,如果可以的话。结果如下:



Klass my_klass = new Klass();



Eclipse具有各种不错的重构功能。是否有这个?

解决方案


  • 右键单击要删除的构造函数 - > Refactor - >更改方法签名。

  • 删除所需的参数(在您的情况下都是这些),然后Eclipse将自动更改对该构造函数的所有调用。如果你已经有一个默认的构造函数,它会抱怨;只需按确定,它将给你一个编译错误,因为你有两个具有相同参数的构造函数,

  • 合并或删除旧的,你有你想要的结果。 / li>

I have an empty constructor for a Class. I want to delete the constructor, but there are many places where I have things such as:

Klass my_klass = new Klass("");

I would like to delete the constructor and have Eclipse automatically refactor if it can. The result would look like:

Klass my_klass = new Klass();

Eclipse has all sorts of nice refactoring features. Does it have this?

解决方案

  • Right click on the constructor you want to remove -> Refactor -> Change method signature.
  • Remove the paramaters you want (all of them in your case) and then your Eclipse will change all of your calls to this constructor automatically. If you already have a default constructor it will complain; just press Ok, it will give you a compilation error because you have two constructor with the same parameters,
  • Make a merge or delete the old one and you have the result that you want.

这篇关于蚀。我可以删除Java类构造函数,使Eclipse自动重构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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