On Nov 10, 2009, at 4:05 PM, gerard davison wrote:
>>
>> <blush/> this is all rather embarrassing...
>
> Well the only place I have ever seen this is in Effective Java 2ed,
> so like you I hadn't heard of this language feature until this year.
> It is very much a language feature that gets lost down the back of
> the sofa. I would guess if you asked 100 java programmers only 1 or
> 2 would have heard of it.
>
> The other solution that occurs to me and I have seen often used is
> to not bind the type in the builder until it is specified see below.
> The trick is to create a new instance of ResponseBuilder when we
> need to bind in the type; and pass in the internal state. Until the
> call to entity(...) the generic parameter T is unbound. (I have
> included the GenericEntity case;
> but I am not sure it would be required if the interface is properly
> generic).
>
Agreed it should not be required. But GenericEntity can still be
useful if T = Object.
>>
>> Unfortunately it is too late to make changes to JAX-RS 1.1. I could
>> add something to Jersey in the interim.
>
> Damm, I figured as much. Do I need to raise this as an issue for
> this for the next release.
Please do.
> I guess I am going to have to wait until 2.x for this. As to a
> workaround, it would be useful the WADL issue, I guess it could as
> simple as a generic subtype of these classes. I guess I will log
> that with the root issue which stated this discussion, hopefully I
> will have this done in a few days.
>
I can add support for GResponse<T> and GResponseBuilder<T> in Jersey.
Ideally i would like those to inherit from Response and
ResponseBuilder but i am not sure that is possible because of method
ambiguity. Given that the simplest thing is to duplicate the
functionality and enable Response to be created from GResponse.
Paul.
> Cheers,
>
> Gerard
>
>>
>> Paul.
>>
>>
>> public class Main {
>>
>> public static class Response<T> {
>>
>> private final T entity;
>>
>> private Response(T entity) {
>> this.entity = entity;
>> }
>>
>> public T getEntity() {
>> return entity;
>> }
>>
>> public static class ResponseBuilder<T> {
>> private T entity;
>>
>> public ResponseBuilder<T> entity(T entity) {
>> this.entity = entity;
>> return this;
>> }
>>
>> public Response<T> build() {
>> return new Response<T>(entity);
>> }
>>
>> static protected <T> ResponseBuilder<T> newInstance() {
>> return
>> RuntimeDelegate.getInstance().<T>createResponseBuilder();
>> }
>> }
>>
>> static public <T> ResponseBuilder<T> start() {
>> return new ResponseBuilder<T>();
>> }
>>
>> }
>>
>> public static class RuntimeDelegate {
>> public static RuntimeDelegate getInstance() {
>> return new RuntimeDelegate();
>> }
>>
>> public <T> Response.ResponseBuilder<T>
>> createResponseBuilder() {
>> return new Response.ResponseBuilder<T>();
>> }
>> }
>>
>> /**
>> * @param args the command line arguments
>> */
>> public static void main(String[] args) {
>> Response<String> r =
>> Response.<String>start().entity("xx").build();
>>
>> String e = r.getEntity();
>> System.out.println(e);
>> }
>> }
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
> --
> 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
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>