這是問題的簡化版本:的Java鑄造/類加載器發出
SomeClass c = (SomeClass) obj.getSomeClassParent()
並不總是,但有時會發生觸發例外
org.somepackage.SomeClass can't be cast to org.somepackage.SomeClass
這怎麼可能?我想這與JAI imageio是原生lib這個事實有關,但轉發這種情況怎麼會發生?我可能錯過了什麼,但是什麼?
I'm using JAI imageio version 1.1
dcm4che 2.0.21 DICOM lib
這裏是原代碼
ImageInputStream iis = ImageIO.createImageInputStream(src);
Iterator<ImageReader> iter = ImageIO.getImageReadersByFormatName("DICOM");
ImageReader reader = iter.next();
DicomImageReadParam param = (DicomImageReadParam) reader.getDefaultReadParam();
而原來的異常
org.dcm4che2.imageio.plugins.dcm.DicomImageReadParam can't be cast to
org.dcm4che2.imageio.plugins.dcm.DicomImageReadParam
Exception Image http://img215.imageshack.us/img215/3894/exception.jpg
可能的重複:http://stackoverflow.com/questions/826319/classcastexception-when-casting-to-the-same-class – 2010-01-08 18:36:21