简体   繁体   English

Netbeans-重构匿名类以分离文件

[英]Netbeans - refactor anonymous class to seperate file

In Netbeans 8.1 in the Java code I have an anononymous inner class that I want to refactor to a named ("normal") class and into a separate file. 在Java代码的Netbeans 8.1中,我有一个匿名内部类,我想将其重构为一个命名(“普通”)类并分解为一个单独的文件。 How can I do this? 我怎样才能做到这一点?

When I do Convert Anonymous to Member it converts the anonymous class to a member class withing the current .java file. 当我执行将匿名者转换为成员时,它会将匿名类与当前的.java文件一起转换为成员类。

匿名转换成会员

在此处输入图片说明 How do I move this now to a separate file? 现在如何将其移动到单独的文件? I can do this of course manually but I would like to do it using the IDE. 我当然可以手动执行此操作,但是我想使用IDE进行操作。

Seems to be a known bug in Netbeans. 似乎是Netbeans中的已知错误。 Further information can be found in: 有关更多信息,请参见:

https://netbeans.org/bugzilla/show_bug.cgi?id=206422 https://netbeans.org/bugzilla/show_bug.cgi?id=206422

The last comment (lytles 2016-04-21 23:14:30 UTC) is from April this year, and gives you a workaround: 最近的评论(lytles 2016-04-21 23:14:30 UTC)是从今年四月开始的,它为您提供了一种解决方法:

the only workaround i can find is to "move inner to outer level", and then "move" the new class (click "To Type") to an existing class. 我能找到的唯一解决方法是“将内部移到外部”,然后将新类“单击”(单击“键入”)到现有的类。 it's far from perfect - the code gets reformatted and the end result is pretty buggy, eg superclass methods get prepended with the class name and don't resolve so i'm then copying and pasting the old code into the new class 这远非完美-代码被重新格式化,最终结果是相当多的错误,例如,超类方法以类名开头且无法解析,因此我将旧代码复制并粘贴到新类中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM