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).

1  
sO convertPrimitiveIfNecessary(O o, Class b) {
2  
  if (b.isPrimitive()) {
3  
    if (o cast Char)  {
4  
      char x = cast o;
5  
      if (b == int.class) ret Int.valueOf(x);
6  
      if (b == long.class) ret Long.valueOf(x);
7  
      if (b == float.class) ret Float.valueOf(x);
8  
      if (b == double.class) ret Double.valueOf(x);
9  
    } else if (o cast Number) {
10  
      if (b == char.class) ret Char.valueOf((char) o.intValue());
11  
      if (b == short.class) ret o.shortValue();
12  
      if (b == int.class) ret o.intValue();
13  
      if (b == long.class) ret o.longValue();
14  
      if (b == float.class) ret o.floatValue();
15  
    }
16  
  }
17  
  ret o;
18  
}

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: 150 / 250
Version history: 11 change(s)
Referenced in: [show references]