gpt4 book ai didi

java - 打印内存地址而不是字符串值

转载 作者:行者123 更新时间:2023-12-01 22:14:43 40 4
gpt4 key购买 nike

我使用以下方法添加到我的 ArrayList“activList”元素:

activList.add(new Fiducial("R600" ));

我使用以下方式打印它:

System.out.println(activList);

这是代码:

// Grid variables
int cols = 10, rows = 10;
int rectangleWidth = 100;
int rectangleHeight = 60;

// these are some helper variables which are used
// to create scalable graphical feedback
int k, l, iD;
float cursor_size = 15;
float object_size = 60;
float table_size = 760;
float scale_factor = 1;
float x, y;


ArrayList<Fiducial> activList = new ArrayList<Fiducial>();

public class Fiducial {

public String type;

public Fiducial(String type) {

this.type = type;
}

}

void draw() {
// Begin loop for columns
for ( k = 0; k < cols; k++) {
// Begin loop for rows
for ( l = 0; l < rows; l++) {
fill(255);
stroke(0);
rect(k*rectangleWidth, l*rectangleHeight, rectangleWidth, rectangleHeight);
}
}




// This part detects the fiducial markers
float obj_size = object_size*scale_factor;
float cur_size = cursor_size*scale_factor;

ArrayList<TuioObject> tuioObjectList = tuioClient.getTuioObjectList();
for (int i=0; i<tuioObjectList.size (); i++) {
TuioObject tobj= tuioObjectList.get(i);
stroke(0);
fill(0, 0, 0);
pushMatrix();
translate(tobj.getScreenX(width), tobj.getScreenY(height));
rotate(tobj.getAngle());
rect(-80, -40, 80, 40);
popMatrix();
fill(255);
x = round(10*tobj.getX ());
y = round(10*tobj.getY ());
iD = tobj.getSymbolID();
activList.add(new Fiducial("R600" ));
fiducialVisibles ();

}

}


void fiducialVisibles () {
System.out.println(activList);
}

但是,它返回类似 [FiducialDetection$Fiducial@47baec4c] 的内容,这似乎是地址。如何检索字符串的实际值?

最佳答案

在您的 Fiducial 类上实现 toString()。

关于java - 打印内存地址而不是字符串值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31328895/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com