public class SortKey { private String category; private Object[] objects; public SortKey(String category, Object... objects) { this.category = category; this.objects = objects; } @Override public String toString() { return (new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)).append(this.category).append(this.objects).toString(); } public String getCategory() { return category; } public void setCategory(String category) { this.category = category; } public Object[] getObjects() { return objects; } public void setObjects(Object[] objects) { this.objects = objects; } }
SortKey sortKey = new SortKey("mama","1","2","3","4","5"); System.out.print(sortKey.toString());
結果:app
SortKey[mama,{1,2,3,4,5}]