Quick Java question.

Louster

One of Freddy's beloved
Joined
Dec 26, 2003
Messages
882
I remember a way of overriding/implementing some method for your own class definitions that would allow the customisation of what it printed when you appended an instance of that particular class to a String (or just printed it or whatever - just the automatic conversion to a String, that in most cases for me at the moment seems to be outputting the memory location or something by default), but I can't for the life of me remember what it was called and googling doesn't seem to be getting me anywhere. Is it something like show, or print, or something?

Oh, and can this same kind of thing be used for enum definitions? I'd like to be able to print something other than the literal string representation of the name of the enum elements I've defined.

Halpe.
 

Louster

One of Freddy's beloved
Joined
Dec 26, 2003
Messages
882
public String toString(){}

Perfect. Thanks.

Does this have an enum analogue? Is it just the same? I've seen some weird enum definitions with all sorts of functionality built right into the declaration but nothing to do with this exactly.
 

Louster

One of Freddy's beloved
Joined
Dec 26, 2003
Messages
882
Nevermind that - got it via google this time. Hooray for enums.
 

Users who are viewing this thread

Top Bottom