-
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!!
-
Re: type casting
By default typecasting works for last returned value...
If you try follwing, it should work...
<javacode>
if( ((CoefficientTerm)terms.firstElement()).isZero() ) {...do something..}
</javacode>
Basically you put parathensis for explicitly specifying which returned value you want to type-cast.
- UnicMan
http://members.tripod.com/unicman