Type primitive pattern: the problem with lossy conversions

Remi Forax forax at univ-mlv.fr
Thu Sep 11 14:30:27 UTC 2025


Following Brian and Dan comments, I restart several different threads.

int to float and long to double (and long to float) are lossy conversions,
for lossy conversions of object, we disallow the corresponding type pattern:

For example:
  List<String> list = ...;
  Object o = list;   // this is lossy
  if (o instanceof List<String> l) {  // this do not compile

but JEP 507 proposes to allow:
  int integer = ...
  float f = integer;  // this is lossy
  if (f instanceof int i) {. // this compile

I do not understand why we should allow the latter code but not the former ?

regards,
Rémi


More information about the amber-spec-observers mailing list