You wrote:
String rep = "Hex: " + this + ", Id: " + this.id;
In java simply writing this
means that you are indirectly invoking this.toString()
.
I believe you are trying to override the toString()
method of Object
and inside your version of toString()
you want to print the id you have passed along with the hashcode
of the object.
So to get the output replace
String rep = "Hex: " + this + ", Id: " + this.id;
with
String rep = "Hex: "+ this.getClass().getName().hashCode() +", Id: " + id;
and you will get the output as:
Hex: 1800024669, Id: 123