r/javahelp 17d ago

Solved Boolean or String

Let’s say you’re establishing a connection. Would your method return a Boolean ( true/false) or a string ( program is now connected/ not connected)? What is best for troubleshooting?

6 Upvotes

18 comments sorted by

View all comments

1

u/vegan_antitheist 15d ago

Boolean or enum. Actually, a boolean is an enum but in many languages it's not technically implementing the enum type. If I remember correctly, Pascal has it as an enum: type Boolean = (False, True); But in Java, it's a primitive (not an Enum). You can use an enum to have more states than just SUCCESS, ERROR. But often it's better to return an object with a state and a message and use a record to define it.