Changes between Version 149 and Version 150 of j2p
- Timestamp:
- 10/17/24 10:08:54 (2 weeks ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
j2p
v149 v150 152 152 But keep reading, the automatic casting is closely related and is more problematic. 153 153 154 === Implicit casting, narrowing 154 === Casting 155 Translation of explicit casting has resonable support. Eg if you write 156 {{{ 157 long x=(long)3; 158 }}} 159 then the translator will convert the int to long. 160 155 161 Java does automatic casting to silently convert between bytes, int, long etc. These can involve narrowing, widening, and potentially lead to conversions or loss of precision etc. There is partial support for these. The translator recognises when such conversion is done and tries to insert extra code to implement the expected narrowing as needed. But the specification has lots of special cases and the implementation is partial. 156 162 157 163 The translator does recognise differences between left and right side in assignments and tries to cast properly. Eg, 158 164 {{{ 159 Float x=3 160 }}} 161 162 it will recognise the right side of the assignment is an int, and convert it to float before assigning into the x. Note that python itself will not give any warning on type errors, this would be fine in python 165 float x=3; 166 }}} 167 168 it will recognise the right side of the assignment is an int, and convert it to float before assigning into the x. Note that python itself will not give any warning on type errors, this would be fine in python: 163 169 {{{ 164 170 x:float=3 … … 172 178 }}} 173 179 174 The call argument, an integer, is in java automatically cast to a float, because that's the actual type required by valueOf. The translator currently does not recognise this case .180 The call argument, an integer, is in java automatically cast to a float, because that's the actual type required by valueOf. The translator currently does not recognise this case and this call would pass an integer into the call. 175 181 176 182 Another example: