简体   繁体   English

Eclipse中未解析的泛型

[英]Generics unresolved in Eclipse

How can I get T to resolve in eclipse? 如何获取T以解决日食?

public T get(Class cl, String id) {
        return ofy().load().type(cl).id(id).get();

    }

Is this not going to work in Java 7? 这在Java 7中行不通吗?

I'm trying to upgrade objectify from 3 to 4. 我正在尝试将对象化从3升级到4。

I think you're asking how to make the method (and Class argument) generic. 我认为您在问如何使方法(和Class参数)通用。 Something like, 就像是,

public <T> T get(Class<T> cl, String id) {
    return ofy().load().type(cl).id(id).get();
}

Generics were introduced in Java 5 (so Java 5+, including Java 7). 泛型是在Java 5(所以Java 5+,包括Java 7)中引入的。

You have to declare it first. 您必须先声明它。

public <T> T get(Class<?> cl, String id) {
        return ofy().load().type(cl).id(id).get();

    }

Or 要么

public class MyClass<T> {
   public T get(Class<?> cl, String id) {
            return ofy().load().type(cl).id(id).get();

        }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM