Android Eclipse: what's the easiest way to duplicate a class?

I am creating several classes that are similar to those that I already have. Right now, right-click the .java file, then select "copy". After that, I right-click and select paste. Then I go on to modify the file. I am doing the same for its corresponding .xml layout file.

I was wondering if there is a smarter way to do this? Perhaps with some additional knowledge to automatically configure a new file semi-automatically?

+6
source share
5 answers

Clicking on the file and pressing Ctrl-C will copy the file. Click on the folder and press Ctrl-V.

+8
source

In the R-Click menu, I could not find the DUPLICATE parameter. But the good old CTR + C , CTRL + V in eclipse does the job.

+1
source

If this is a class that you want to copy very often ... this is possibly the functionality and behavior that you want in the copied classes. This is very easy to do using inheritance.

So, create a class that has common functionality as a superclass and let all classes that need these functions extend it. All this.

Copying and pasting is not a good idea .. because you will distribute the same logic in several files, which will hurt if you want to change any behavior - you will have to edit all the copied files. Inheritance will keep them in one place.

0
source

I often have to do this for inner classes, not for duplicate files. Here is how I do it:

  • Open Scheme ( Ctrl-W O )
  • Select an inner class in the Structure view
  • Copy ( Ctrl-C )
  • Choose top level class
  • Paste ( Ctrl-V )

This creates a new inner class inside the top-level class.

0
source

Source: https://habr.com/ru/post/892872/


All Articles