Curt,
Thanks for your help on this issue. It was much appreciated
Regards,
Pat
Curt Springer <[EMAIL PROTECTED]> wrote:
>This was covered in either/both of the ND 3->4 migration course and the ND>3->4
>conversion guide
>
>You wrote breakable code. Sometimes breakable code breaks, and sometimes
>it doesn't.
>
>If X is an abstract class that is extended by concrete classes X1, X2, X3,
>etc., and there is a method getX() that returns an object of class X, it
>could be any one of the concrete classes. In fact, it might even be an
>anonymous inner class that you've never heard of. If you just cast the
>return to X1 without checking, and, if it is X1, then stuff will work. If
>it is not X1, then a class cast exception will be thrown.
>
>In ND3, 99% of the time, methods that returned CSpValues actually returned
>CSpStrings. But there was never a guarantee that you would get a CSpString
>and not a CSpInteger or whatever. In ND4, you are getting more returns
>that are not CSpStrings. It has to do with the new architecture that
>employs tndValues and stuff (not well documented IMHO) under the hood.
>
>I would also suggest that you look at how you are using CSpValues in
>general. There's not much point to them, any more. I'm hoping that in the
>future ND will give us the option of using Object (and its children String,
>Integer, Vector, etc.) instead of CSpValue. If you need to deal with a
>CSpValue as a specific concrete extension (e.g. CSpString), think about
>just using the generic java equivalent (e.g. String), instead.
>
>-- Curt Springer, Team ND
>
>
>At 07:19 AM 4/16/99 -0800, Pat_ORourke wrote:
>>Curt,
>>
>>Thanks for that. That appeared to work fine. However, would you have any
>idea why the previous
>>casting code would work in ND3 and not in ND4. I am currently migrating an
>ND3 project to ND4 and the
>>casting that I described earlier is dotted all over the place and this
>would involve quite of lot
>>of searching and replacing if this is the case.
>>
>>Thanks,
>>Pat.
>>
>>Curt Springer <[EMAIL PROTECTED]> wrote:
>>>At least in this instance, your method is returning a CSpValue that
>is>_not_ a CSpString.
>>>
>>>If you want to guarantee that you get a CSpString result, you would have to
>>>do:
>>>CSpString min = new CSpString(fdMinInputSizeBank.get( fieldName )
>>>.stringValue());
>>>
>>>If you have reason to believe that the method would actually return a
>>>CSpString a good deal of the time, and don't want to incur the overhead of
>>>instantiating a new one all the time, you could test:
>>>CSpValue min1 = ( fdMinInputSizeBank.get( fieldName ));
>>>CSpString min = min1 instanceof CSpString ? min1 : new
>>>CSpString(min1.stringValue());
>>>
>>>-- Curt Springer, Team ND
>>>
>>>At 05:15 AM 4/16/99 -0800, Pat_ORourke wrote:
>>>>I am trying to cast a CSpValue to a CSpString and the below code is giving
>>>me the following error.
>>>>
>>>>'Unexpected Exception (java.lang.ClassCastException:
>>>spider.session.CSpLong) caught.
>>>>Top of stack: |java.lang.ClassCastException: spider.session.CSpLong'
>>>>
>>>>
>>>>// Exception thrown here
>>>>CSpString min = (CSpString) (fdMinInputSizeBank.get( fieldName ) );
>>>>
>>>>// I placed this debug code in the function to check that a value exists.
>>>>// This prints the value from the database table (eg '10') to the log
>>>file with no exception
>>>>CSpValue min1 = ( fdMinInputSizeBank.get( fieldName ));
>>>>CSpLog.send( "pgBoResellerDetails", CSpLog.ERROR, min1 );
>>>>
>>>>
>>>>(Aside : fdMinInputSizeBank is a hash table that stores the minimum value
>>>>for a particular field)
>>>>
>>>>Any ideas would be appreciated,
>>>>Thanks,
>>>>Pat.
>>>>_________________________________________________________________________
>>>>
>>>>For help in using, subscribing, and unsubscribing to the discussion
>>>>forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
>>>>
>>>>For dire need help, email: [EMAIL PROTECTED]
>>>>
>>
>>_________________________________________________________________________
>>
>>For help in using, subscribing, and unsubscribing to the discussion
>>forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
>>
>>For dire need help, email: [EMAIL PROTECTED]
>>
_________________________________________________________________________
For help in using, subscribing, and unsubscribing to the discussion
forums, please go to: http://www.netdynamics.com/support/visitdevfor.html
For dire need help, email: [EMAIL PROTECTED]