How can I make a string of objects names in java -


i write function enable me following

  1. inputs: variable number of objects of type
  2. output: string nameobj1=valueobj1, ..., nameobjn=valueobjn

all objects pass function have tostring() method.

example:

double x=1.1; int y=2; classa  thefunction(x,y,a) => output "x=1.1, y=1, a=[whatever a.tostring() output]" 

is possible ?

here's close:

you can write var-arg function so:

public static string describearguments (object... arguments) {    stringbuilder output = new stringbuilder();    int counter = 1;    (object argument : arguments) {       output.append("object #").append(counter++).append(": ").append(argument.tostring());    }    return output.tostring(); } 

strictly speaking method arguments dont have names. retrieve argument parameter name using reflection if symbol tables werent stripped out @compile time, brutish , ugly.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -