OCPJP 6.0-81% | Preparing for OCWCD
http://www.certpal.com/blogs/cert-articles | http://sites.google.com/site/mostlyjava/scwcd |
Matthew Brown wrote:
You can't convert an Object array into a String array just because it contains only Strings. You have to have created a String array in the first place for the cast to work.
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
Imad Aydarooos wrote:Even if he has already created the String[] before he cast, this will not work. WHY?? because String IS A Object, so you can cast an Object to String, but String[] IS NOT A Object[]
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
Imad Aydarooos wrote:
and I got this:
C:\myprogs>java Question24_toArray_Ask
Exception in thread "main" java.lang.ClassCastException: [Ljava.lang.Object; can
not be cast to [Ljava.lang.String;
at Question24_toArray_Ask.main(Question24_toArray_Ask.java:19)
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
expect the Object[] elements which are Object type to be automaticly casted to String, but this dosn't happen
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
love demgracy, knowledge demogracy, open source and Java - OCPJP 76%
SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Consider Paul's rocket mass heater. |