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

16
LINES

< > BotCompany Repo | #1001985 // instanceOf

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

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

// not a very good one
sbool instanceOf(O o, S className) {
  if (o == null) false;
  S c = o.getClass().getName();
  ret eq(c, className) || eq(c, "main$" + className);
}

// better
sbool instanceOf(O o, Class c) {
  if (c == null) false;
  ret c.isInstance(o);
}

sbool instanceOf(Class c, O o) {
  ret instanceOf(o, c);
}

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001985
Snippet name: instanceOf
Eternal ID of this version: #1001985/3
Text MD5: 306ee85dcb07940a18b48cf389b37131
Transpilation MD5: 89ff7307d686b4d0e42bd96ae35932e0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-01-23 20:48:49
Source code size: 339 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 661 / 1256
Version history: 2 change(s)
Referenced in: [show references]