Firstly, your C # example is incorrect; he will throw InvalidCastException, if only typeof(T) == typeof(object). You can fix this by adding a restriction :
public static T Resolve<T>() where T : new() {
return new T();
}
Now this will be the equivalent Java syntax (or at least as close as possible):
public static <T> T Resolve() {
return (T) new T();
}
Note the double mention Tin the declaration: one is Tin <T>, which parameterizes the method, and the second is the return type T.
, Java. - , Java , T , . :
public static <T> T Resolve(Class<T> c) {
return c.newInstance();
}
T.class. . .