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


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.


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.


Thanks for answering 😊


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


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


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