jjzjj

castToAnotherType

全部标签

java - Java 泛型中没有抛出 ClassCastException

下面是我写过的第一个Java泛型:publicclassMyClass{publicstaticTcastToAnotherType(Objectparam){Tret=null;try{ret=(T)param;}catch(ClassCastExceptione){System.out.print("ExceptioninsidecastToAnotherType()");}returnret;}publicstaticvoidmain(String[]args){try{Stringobj=MyClass.castToAnotherType(newObject());}catch