가능한 중복 :자바에서 T.class를 작성하는 방법은 무엇입니까?
에서
how to get class instance of generics type T
템플릿의 T
JAXBContext jaxbContext = JAXBContext.newInstance(T.class);
이 T.class를 컴파일 할 수 없습니다, 그것은 반사와 방법이 필요합니까?
public void ConvertObjectToXML(String path, T bobject)
{
//Convert XML to Object
File file = new File(path);
JAXBContext jaxbContext = JAXBContext.newInstance(T.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
T customer2 = (T) jaxbUnmarshaller.unmarshal(file);
System.out.println(customer2);
}
'T'참조 란 무엇입니까? 일반 (T.class 참조 때문에)처럼 보이지 않습니다. 그걸 어떻게 들으니? –
T는 수업이 아닙니다. 그렇습니까? –
'T '는 제네릭 타입이라고 생각 하나? 이 경우'T.class'가 유효하지 않으므로 위의 코드는 컴파일되지 않습니다. 이는 유형 삭제 때문입니다. 런타임에 제네릭 클래스가 필요한 경우 여기를 참고하십시오 : http://stackoverflow.com/questions/2225979/getting-t-class-despite-javas-type-erasure –