How can I get T to resolve in eclipse?
public T get(Class cl, String id) {
return ofy().load().type(cl).id(id).get();
}
Is this not going to work in Java 7?
I'm trying to upgrade objectify from 3 to 4.
I think you're asking how to make the method (and Class
argument) generic. 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).
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.