Two java classes with different annotation values only Consider two classes:

First

@Path("/first/{param}") // 1st line
public class First {

    @GET
    @Path("/{data}/difference") // 5th line
    public Response doStuff(
            @Context HttpServletRequest request,
            @Context UriInfo uri,
            @Context HttpHeaders httpHeaders,
            @PathParam("param") String param,
            @PathParam("data") String data
    ) {

        // whatever
        return new Response();

    }

}


Second

@Path("/second/{param}") // 1st line
public class Second extends First {

    @GET
    @Path("/{data}") // 5th line
    public Response doStuff(
            @Context HttpServletRequest request,
            @Context UriInfo uri,
            @Context HttpHeaders httpHeaders,
            @PathParam("param") String param,
            @PathParam("data") String data
    ) {

        return super.doStuff(
            request,
            uri,
            httpHeaders,
            param,
            data
        );

    }

}


The only differences between this two block of code are:


@Path() annotation value in the 1st line of both of them
@Path() annotation value in the 5th line of both of them


How can I remove all the redundant code from it?
You can parameterize the @path annotation with regular expressions to specify one class/method that accepts multiple paths 

@Path("/{firstpath: first|second}/{param}") // will match /first/{param} and /second/{param}
public class First {

    @GET
    @Path("/{data}{p:/?}{difference:(\w*)}") // {p:/?} makes "/" optional, {difference:(\w*)} allows for optional text
    public Response doStuff(
            @Context HttpServletRequest request,
            @Context UriInfo uri,
            @Context HttpHeaders httpHeaders,
            @PathParam("param") String param,
            @PathParam("data") String data
    ) {

        // whatever
        return new Response();

    }

}