编译代码时,我收到了关于Object Casting的警告消息.我不知道如何使用我目前的知识修复它....假设我有一个通用对象MyGenericObj<T>它是从非通用对象扩展的MyObj
这是一个示例代码:
MyObj obj1 = new MyGenericObj<Integer>();
if (obj1 instanceof MyGenericObj) {
//I was trying to check if it's instance of MyGenericObj<Integer>
//but my IDE saying this is wrong syntax....
MyGenericObj<Integer> obj2 = (MyGenericObj<Integer>) obj1;
//This line of code will cause a warning message when compiling
}
Run Code Online (Sandbox Code Playgroud)
能不能让我知道这样做的正确方法是什么?
任何帮助表示赞赏.