我想知道這段代碼幹什麼?它打印所有TreeSet的幾個? 它真的可以用System.out.println打印TreeSet嗎?system.out.println(tresset對象)
public static void main(String[] args) {
TreeSet <Moulage> treeSetMoulages = new TreeSet <Moulage>();
Moulage moulage = new Moulage ("REF24", "Cervidé","Bronze");
treeSetMoulages.add(moulage);
moulage = new Moulage ("REF44", "Insigne de chefferie","Bois");
treeSetMoulages.add(moulage);
moulage = new Moulage ("REF63", "Panthere","Marbre");
treeSetMoulages.add(moulage);
moulage = new Moulage ("REF58", "Ours blanc","Marbre");
treeSetMoulages.add(moulage);
moulage = new Moulage ("REF78", "Danseuse","Bronze");
treeSetMoulages.add(moulage);
System.out.println (treeSetMoulages);
}
我如何知道它是否可打印類? – youngknight
@youngknight如果你已經實現了'toString'方法。 System.out.println(object)在對象上調用'toString'方法。 –