0

I hate working with parametrics, they are open doors for bad code practices and mistakes. However people do use them often so I try to live with it.

I am struggling to solve this warning condition, however I have no idea how to properly fix this.

enter image description here

/**
 * Enables incoming connections from any remote address and disables authentication (cross-origin access should be blocked
 * when entering in production).
 * 
 * @param serverResource
 * @return
 */
private static Series<Header> configureRestForm(ServerResource serverResource) {
    final Object responseHeaders = serverResource.getResponse().getAttributes().get("org.restlet.http.headers");
    final Series<Header> headers;
    if (responseHeaders instanceof Series<?>) {
        headers = (Series<Header>) responseHeaders;
    } else {
        headers = new Series<Header>(Header.class);
        serverResource.getResponse().getAttributes().put("org.restlet.http.headers", headers);
    }
    headers.add("Access-Control-Allow-Origin", "*");
    headers.add("Access-Control-Allow-Methods", "GET, POST, PUT, OPTIONS");
    headers.add("Access-Control-Allow-Headers", "Content-Type");
    headers.add("Access-Control-Allow-Credentials", "false");
    headers.add("Access-Control-Max-Age", "60");
    return headers;
}

What should I do?

Thanks!

PedroD
  • 4,310
  • 8
  • 38
  • 75
  • one possibility: add SupressWarnings as annotation to the method as you can see in the warning dialog itselfs. – s_bei Jan 15 '16 at 11:25
  • each cast is dirty. another possibility is the adapter pattern. – s_bei Jan 15 '16 at 11:26
  • 2
    You have to cast.. there is no other possibility as serverResource.getResponse().getAttributes() returns an object. Applying SupressWarnings will make eclipse recognize that you have accepted defeat and allowed the warning to remain there.. – awsome Jan 15 '16 at 11:34
  • Possible duplicate of [Type safety: Unchecked cast](http://stackoverflow.com/questions/262367/type-safety-unchecked-cast) – leonbloy Jan 15 '16 at 12:18

1 Answers1

1

You can use @SuppressWarnings("unchecked") annotation or try change Eclipse preferences: Java->Compiler->Errors/Warnings->Generic types and check the Ignore unavoidable generic type problems check-box

Javasick
  • 1,951
  • 1
  • 19
  • 27
  • In the code you can use only SuppressWarnings annotation. There is no another solution for parameterised generics (Map or List etc) – Javasick Jan 15 '16 at 14:02