toString in java - System.out.println vs log in Android -
lets assume have following class definition:
class test{ public string tostring(){ return "hello test"; }
now class following:
test mytest=new test(); //output of below 'hello test' system.out.println(mytest);
i looking equivalent in android on objects:
log.d("tag",mytest); or createtoast(context,mytest,toast.short).show();
i dont want have call objects tostring method, want dump object method , knows needs call tostring system.out.println did.
since log.x takes string second parameter, you'd better wrapper calls android logger, like:
static class mylogger{ public static void d(string tag,object o){ if(o==null){ throw new nullpointerexception("the second parameter can not null"); } log.d(tag, o.tostring()); } }
Comments
Post a Comment