The strange case of the cast that always fails

From AWiki

Jump to: navigation, search
public class AClass {
	...
	public void aMethod(final Object obj) {
		...
		if(!obj instanceof InterfaceXYZ) {
			final InterfaceXYZ xyz = (InterfaceXYZ)obj;
			...
		}
		...
	}
}

The peculiarity oh this piece of code is that it has origin from production-code. It's fairly common make a mistake in a conditions during development... but is not very usual to find an always failing cast in code delivered into production.

Personal tools