Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Any's methods are not abstract or native?

Java

Source

Object's methods are marked as native, so it's easy to understand they are implemented behind the scene

Kotlin

Source

   public open class Any {
        public open operator fun equals(other: Any?): Boolean
        public open fun hashCode(): Int
        public open fun toString(): String
    }

Any's methods are not marked as native or abstract, so question is next:

When and how Any's methods are generated and why I can't just copy-paste Any class and compile without errors?

like image 386
Roman Svyatnenko Avatar asked Dec 24 '22 04:12

Roman Svyatnenko


1 Answers

Any's methods are not generated. The compiler maps Any to java.lang.Object, which provides the implementations of methods as part of the JDK.

The methods are not marked as abstract, because Any is not an abstract class. The methods are not marked as native because the mapping of Kotlin standard library classes to JDK classes is not unique to the Any class, and other methods mapped in a similar way are not native.

like image 56
yole Avatar answered Jan 09 '23 17:01

yole