Changes between Version 149 and Version 150 of j2p


Ignore:
Timestamp:
10/17/24 10:08:54 (2 weeks ago)
Author:
wouter
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • j2p

    v149 v150  
    152152But keep reading, the automatic casting is closely related and is more problematic.
    153153
    154 === Implicit casting, narrowing
     154=== Casting
     155Translation of explicit casting has resonable support. Eg if you write
     156{{{
     157long x=(long)3;
     158}}}
     159then the translator will convert the int to long.
     160
    155161Java 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.
    156162
    157163The translator does recognise differences between left and right side in assignments and tries to cast properly. Eg,
    158164{{{
    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
     165float x=3;
     166}}}
     167
     168it 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:
    163169{{{
    164170x:float=3
     
    172178}}}
    173179
    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.
     180The 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.
    175181
    176182Another example: