On 12/11/2009 11:17, Paul Sandoz wrote:
>>
>> Can you give an example of this? Won't most cases work with just a 
>> cast as you already know the type for a generic entity.
>>
>
>   @GET
>   public Object get() {
>   }
>
> Object can be an instance of Response, GenericEntity or something 
> else. GenericEntity is also useful on the client side.
Yup, sorry forgot about that case.
> Covariant return types should make it possible to create a subclass of 
> ResponseBuilder that returns a more specific type.
>>
>
> To the caller methods will be ambiguous:
>
>     public abstract class GResponse<T> extends Response {
>
>         public static <T> GResponseBuilder<T> status(int status) {
>            ...
>         }
>
>         ...
>
>     }
>
> The following line will not compile:
>   
>     GResponse<String> r = GResponse.<String>status(200).build();
>
> Paul.
I had a little bit of a play with this and came up with an example that 
appears to build. I might again be missing some important step as I 
haven't built a fully working example.
Cheers,
Gerard
import java.net.URI;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import javax.ws.rs.core.CacheControl;
import javax.ws.rs.core.EntityTag;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.NewCookie;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Variant;
public abstract class GenericResponse<T> extends Response {
    public abstract T getEntity();
    public static <T> GenericResponseBuilder<T> status(int p1) {
        return null; // Return some kind of trivial wrapper of the 
ResponseBuilder
    }
   
    public static abstract class GenericResponseBuilder<T> extends 
Response.ResponseBuilder {
        public abstract GenericResponse<T> build();
        public abstract GenericResponseBuilder<T> status(int i);
         // ..... All the other methods with the new return type
    }
   
   
    public static void main(String[] args) {
        GenericResponse<String> r = GenericResponse
                              .<String>status(200) // Return a 
GenericResponseBuilder<String>
                              .build();  // Return a GenericResponse<String>
    }
}
-- 
Gerard Davison | Senior Principal Software Engineer | +44 118 924 5095
Oracle JDeveloper Web Service Tooling Development
Oracle Corporation UK Ltd is a company incorporated in England & Wales.
Company Reg. No. 1782505.
Reg. office: Oracle Parkway, Thames Valley Park, Reading RG6 1RA.
Blog http://kingsfleet.blogspot.com