我是C#转Java的,发觉Java的泛型写起来有点奇怪,求助,下面这个问题应该如何解决。
定义的方法:
public static <T> T FromJson(String json)
{
T obj = JSON.parseObject(json, new TypeReference<T>() {});
return obj;
}
使用的时候报错
MyClass cls2 = JsonClass.FromJson<MyClass>(str);
提示是<MyClass>
这个地方错误,如果删掉,就语法上正确,但是实际运行会错误。
我是按照C#逻辑来理解些的,貌似Java不是这么一回事?
So your compilation error is because you are using it in the wrong way.
As for when you get an error when running, you should post the error message to see what went wrong.
There is no need to specify generics when using the method
I don’t know if this is possible