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

14
LINES

< > BotCompany Repo | #1025941 // stdToStringWithFields - stringify an object like a record, showing certain fields only

JavaX fragment (include)

sS stdToStringWithFields(O o, S... fields) {
  if (o == null) ret "null";
  S name = shortClassName(o);
  
  // new default
  if (empty(fields)) fields = asStringArray(allNonStaticFields(o));
  
  if (empty(fields)) ret name;
  ret name + "(" + joinWithComma(mapNonNulls(fields, field -> {
    O value = getOpt(o, field);
    if (value == null) null;
    ret field + "=" + str(value);
  })) + ")";
}

Author comment

Began life as a copy of #1022820

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1025941
Snippet name: stdToStringWithFields - stringify an object like a record, showing certain fields only
Eternal ID of this version: #1025941/6
Text MD5: 43b7d024e6edc6833eb570a894e8fa40
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-10-11 01:02:37
Source code size: 412 bytes / 14 lines
Pitched / IR pitched: No / No
Views / Downloads: 157 / 194
Version history: 5 change(s)
Referenced in: [show references]