我想创建一个具有返回类对象的自定义数据类型的类。考虑一个自定义类:
public class Custom {
// Some fields.
public Custom(String custom) {
// Some Text.
}
// Some Methods.
public void customMethod() {
// Some Code.
}
}
现在,考虑第二类 TestCustom:
public class TestCustom {
public static void main(String[] args) {
Custom custom = new Custom("Custom");
System.out.println(custom); // This should print "Custom"
custom.customMethod(); // This should perform the action
}
}
因此,问题是如何在实例化对象而不是内存位置时获得自定义值。就像我得到的是:
Custom@279f2327