Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

18
LINES

< > BotCompany Repo | #1034751 // convertPrimitiveIfNecessary

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (45L/1K).

sO convertPrimitiveIfNecessary(O o, Class b) {
  if (b.isPrimitive()) {
    if (o cast Char)  {
      char x = cast o;
      if (b == int.class) ret Int.valueOf(x);
      if (b == long.class) ret Long.valueOf(x);
      if (b == float.class) ret Float.valueOf(x);
      if (b == double.class) ret Double.valueOf(x);
    } else if (o cast Number) {
      if (b == char.class) ret Char.valueOf((char) o.intValue());
      if (b == short.class) ret o.shortValue();
      if (b == int.class) ret o.intValue();
      if (b == long.class) ret o.longValue();
      if (b == float.class) ret o.floatValue();
    }
  }
  ret o;
}

download  show line numbers  debug dex  old transpilations   

Travelled to 3 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034751
Snippet name: convertPrimitiveIfNecessary
Eternal ID of this version: #1034751/12
Text MD5: c2cff867fa62512a72e5085b2e59bfcc
Transpilation MD5: e6dcdffd21fe34a9f4462b1ab8a62d14
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-08 03:08:04
Source code size: 636 bytes / 18 lines
Pitched / IR pitched: No / No
Views / Downloads: 149 / 249
Version history: 11 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)