Harry Tuttle
October 1st, 2000, 11:09 AM
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!!
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!!