Is it possible to extend a Java class with the same name

I work with a ridiculously large code base and I need to move the file from one package to another. However, I don't have the entire code base locally, so I'm not sure if I found and updated every link to the source file. To ensure that I don't break anything, I would like to leave the original file and just extend the new file that I created. Ideally, they would have the same name. Overtime, I plan to refuse and delete the old file, but at the moment this seems like the most reliable solution. However, I cannot figure out how to make it work in Java.

Here is a new class:

package myproject.util.http;

import javax.servlet.http.HttpServlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public abstract class MyServlet extends HttpServlet
{

    public void service (HttpServletRequest  request,
                         HttpServletResponse response)
            throws ServletException, IOException
    {
        // implementation of service
    }

}

Here is an old class that extends the new:

package myproject.util.net;

import myproject.util.http.MyServlet;

public abstract class MyServlet extends myproject.util.http.MyServlet
{
// this class was deprecated, use myproject.util.http.MyServlet instead
}

Sorry, I get an error message:

MyServlet is already defined in this compilation unit

Is this possible, or will I have to come up with a new name for the parent class.

+5
3

, import.

, , : , MyServlet, .

+5

, , , .

0

Just delete the import and get the full name myproject.util.http.MyServlet

0
source

All Articles