+1

Can anyone help me in this : 'Any' keyword in kotlin

Can you help me out in this... If Any keyword allows anything than why this doesn't works.. fun takeAny(arg: Any) { println(arg); } fun main(args: Any) { takeAny("Some string"); takeAny(42); } /* Change : Array<String> to Any*/ https://www.sololearn.com/learn/8793/?ref=app

4/2/2020 6:24:54 AM

Akshay Jain

6 Answers

New Answer

+4

It works fine. But, JVM looks for main with Array<String> parameter and fails to find it. You can overload main same as any function and call the Any one from the Array<String> one to prove that fact.

+3

To be a valid main entry point, the prototype must be using Array<String>. You can change args to any name. But, the function will only be found with that type on it's argument. This is a limitation in the Java Virtual Machine (JVM) code.

+2

Thanks for answering 😊

+2

Any is not a keyword it is a super class of classes available in kotlin and if you creat any class for example (MyClass) than by default it will be extends (Any) class

+2

ohh.. it wasn't mentioned anywhere. Thanks for telling

+1

John Wells so 'Any' Keyword not works for predefined functions..Is it??