devxlogo

Write One toString() Method for Most All Your Classes

Write One toString() Method for Most All Your Classes

 public String toString(){	StringBuffer sb = new StringBuffer( 256 );	sb.append("[Field Name]	[Value]
");	Class curr = this.getClass();	while(curr != null){		Field[] field = curr.getDeclaredFields();		for(int i=0; i
" );			}			catch(IllegalAccessException iae){				sb.append( "IllegalAccessException
" );			}		}		curr = curr.getSuperclass();			//Recurse super classes	}//end while	return sb.toString();}//end toString()

devx-admin

Share the Post: