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

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -