如何在restTemplate中使用java泛型

时间:2016-08-16 17:14:37

标签: java generics resttemplate

我创建了一个执行方法,我在其中传递了我的restTemplate实例以及类obj。但是,我收到一些关于未经检查的类型的警告。我似乎无法弄清楚如何使用泛型来做到这一点。这是我到目前为止所做的:

public class RepositoryUtils {

    private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryUtils.class);

    public static ResponseEntity execute(String url, RestTemplate restTemplate, Class generic) {

        LOGGER.info("GET: {}", url);

        ResponseEntity response = null;
        try {
            response = restTemplate.exchange(url, HttpMethod.GET, RequestHelper.getGzipHttpEntity(), generic);
        } catch (Exception e) {
                LOGGER.error("RestTemplate: {} - {}", url, e.getMessage());
        }

        return response;
    }
}

以下是我如何调用静态执行:

ResponseEntity<Channels> response = RepositoryUtils.execute(channelUrlFinal, restTemplate, Channels.class);

1 个答案:

答案 0 :(得分:2)

以下是您可以尝试作为方法的签名:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.NATester/android.app.NativeActivity}: java.lang.IllegalArgumentException: Unable to load native library: /data/app/com.NATester-2/lib/x86/libNATester.so