我有无法在数组的对象元素中调用我自己的方法的问题
这是包含数组的部分代码的代码:
public class CardRules {
private Object cardArray[];
public CardRules(Object cardArrayCopy[]){
cardArray = cardArrayCopy;
multiples();
}
public void multiples(){
for(Object ArrayElement: cardArray){
System.out.println(ArrayElement);
}
}
}
对于卡片对象:
public class Card {
private int rank;
private int suit;
private String Stringrank[] = {"Ace", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Jack", "Queen", "King"};
private String Stringsuit[] = {"Spades", "Hearts", "Diamonds", "Clubs"};
public static int CardNo = 0;
public Card(int cardDetails[]){
rank = cardDetails[1];
suit = cardDetails[0];
CardNo++;
}
public String getCard(){
return ("Card: " + Stringrank[rank] + " Of " + Stringsuit[suit]);
}
public int getRank(){
return rank;
}
public int getSuit(){
return suit;
}
}
这部分程序的输出是哈希码 Card@9304b1 Card@190d11 Card@a90653 Card@de6ced Card@c17164
我想放一些类似或类似的东西
System.out.println(ArrayElement.getRank());
有没有人知道为什么会这样?
顺便说一句,数组是使用预制的 .toArray() 方法从另一个类中的 ArrayList 复制的