您对 Clip 类的实现是错误的。它应该是这样的:
public class Clip {
private String title;
private String author;
public Clip(String title, String author) {
this.title = title;
this.author = author;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
您可以像这样从数组中检索对象:
@Test
public void testClipArray() throws Exception {
// Lets assume our array contains 2 elements
Clip[] clipArray = new Clip[2];
clipArray[0] = new Clip("First", "Clip");
clipArray[1] = new Clip("Second", "Clip");
// Lets retrieve 2nd object (with index: 1)
Clip secondObject = clipArray[1];
System.out.println(secondObject.getAuthor());
System.out.println(secondObject.getTitle());
}