Rather than implicit conversion, is there a way to force the java compiler to issue an error when variables types do not match. For example:
int intValue=3;
double dblValue = 2.2;
double result;
result = 1/intValue*(intValue-dblValue);
In the example above java will implicitly convert (1/intValue) to an integer with the value 0.
What I want is for the compiler to issue an error when variable types don't match rather than implicitly converting.
Thanks in advance
Edit1: The equation above is just an example. I do know how to fix this issue by using either one of the solutions below:
result = 1.0/intValue*(intValue-dblValue);
or
result = 1/(double)intValue*((double)intValue-dblValue);
but thats not what I'm after. Thanks
Edit2: I was referring to type conversion not type casting. I'm looking for the compiler to enforce explicit type conversions.
I'm looking for something like this: https://support.microsoft.com/en-us/help/311329/option-explicit-and-option-strict-in-visual-basic-.net-and-in-visual-basic