Wish IDE warning when narrowing takes place

moster67

Expert
Licensed User
Longtime User
in B4X (not sure about B4R), B4x casts types automatically as needed. It also converts numbers to strings and vice versa automatically.
This is convenient but can also be dangerous due to loss of data.

B4X:
Private i As Int = 50000
Private s As Short = 0
s = i
Log(s) '-15536

In Java, those conversions that may lose data are called narrowing and must be explicitly demanded by the programmer using a cast

B4X:
 int i = 50000;
short s = 0;
//s = i; //error when writing code
s = (short) i; //explicit casting
System.out.println(s); //-15536

Would it be possible to implement that the IDE issues a warning when narrowing takes place?
 
Last edited:
Top