Do return types really matter ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Do return types really matter ?

My real question is this: Does specifying a return type only matter if you're dealing with integers or doubles ?

25th Apr 2018, 1:30 AM
Edward
Edward - avatar
3 Answers
+ 3
if your return type is not void you must have a return statement you can return each object not only int or double also strings arrays lists and so on and in java you need a return type
25th Apr 2018, 1:36 AM
Stefanoo
Stefanoo - avatar
+ 1
If you want the function to return a value to after calculating then it matters. If you don't need a value than use void.
25th Apr 2018, 1:37 AM
Akib
Akib - avatar
+ 1
Return types are often important. Boolean particularly useful for knowing if a function succeeded or not. We mustn't assume functions always do what we want (if they get unusual or unexpected input, they may fail). If they fail, they might pass the mess onto the next function, which could cause further problems. Always check status codes where possible. Exceptions can be used to in some circumstances.
25th Apr 2018, 1:38 AM
Emma