java - inconvertible types but without warning or error? -


during code review found line of code:

sctyp lsctyp = (sctyp) (lworkspace.getsctyp() == null ? chartfactory.blank_string : lworkspace.getsctyp()); 

i little bit confused becouse line of code leads failed hudson build in regarding project. reason: inconvertible types

i know typecast completly wrong here. if getsctyp() null try cast string (chartfactory.blank_string) sctyp.

why doesnt eclipse show error or @ least warning in line of code?

since ternary operator can evaluate either string or getsctype returns, gets evaluated object reference. alright cast object reference other type.

another way view line be

object temp = lworkspace.getsctyp() == null ? chartfactory.blank_string : lworkspace.getsctyp(); sctyp lsctyp = (sctyp)temp; 

if both paths through ternary operator returned sctyp, there have been no need cast.

i'm guessing eclipse did display error before cast added, , fixed error adding cast. hid real error.


Comments