Skip to content
Sign upLog in
← Back to Community

please find the error and submit

Profile icon
AnishChaudhary

type checks and automatic casts
i was practicing this and couldn't solve this please solve

Voters
Profile icon
AnishChaudhary
Comments
hotnewtop
Profile icon
AmoghTheCool

the bug here is that you are not calling the functions in the main function as you should be doing. An error-free version of this would be:

fun getStringlength(obj:Any):Int?{ if (obj is String && obj.length>0){ return obj.length } return null } fun main(){ fun printLength(obj:Any){ println("Getting the length of '$obj'.Result: ${getStringlength(obj) ?:"Error: The object is not a string"} ") } printLength("Incomprehensibilities") printLength("") printLength(1000) }
Profile icon
AmoghTheCool

Select this as the correct answer if it helps!

Profile icon
AnishChaudhary

@AmoghTheCool
bro do you know swing, help me to embed images
check my repl
repl name : creating a simple gui part 2

Profile icon
AmoghTheCool

@AnishChaudhary
sorry, no i don't. I have decent experience in Kotlin/Android, tho. I don't do java.

this is a good video EXACTLY fitting your needs.