|
-
October 1st, 2000, 11:09 AM
#1
type casting
Hi. I was wondering if there is a way to make the following line of code work.
if( ( CoefficientTerm) terms.firstElement().isZero() ) {...do something..}
In the program, term.firstElement() returns an Object that is typecast to (CoefficientTerm). Then, isZero returns a boolean. As it is the expression gives me a compile error saying that I can't convert a CoefficientTerm to a boolean. I could fix the problem by breaking it into two lines like:
newCoef = (CoefficientTerm) terms.firstElement();
if ( newCoef.isZero() ){ ... }
However, there must be a better way. So is there anyway to typecast just the first part of an expression, but not the rest?
Thanks a lot!!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|