建立下三個類(文件那種)
public class Dto {
public String hehe;
public String getHehe() {
return hehe;
}
public void setHehe(String hehe) {
this.hehe = hehe;
}
}
2.R.java
public class R {
public void hehe() {
String test = "test";
Dto dto = new Dto();
dto.setHehe(test);
}
}
3.Main.java
public class Main {
public static void main(String[] args) {
R r = new R();
r.hehe();
Dto dto = new Dto();
System.out.print(dto.getHehe());
}
}
最後想要的結果是test 但卻是null,求解為什麼和解決方案
public class R {
public void hehe(dto) {
String test = "test";
dto.setHehe(test);
}
}
public class Main {
public static void main(String[] args) {
R r = new R();
Dto dto = new Dto();
r.hehe(dto);
System.out.print(dto.getHehe());
}
}