Why it is possible to build custom language for JVM, like Groovy, Scala, Clojure, Kotlin?

221 views Asked by At

These languages differ from Java in significant ways, like OO system, type system (most notable).

The actual question is whether JVM keeps track of objects under the hood? Is there an object inside JVM? Is it responsibility of creators of such languages that they may interoperate with Java world, or it is achieved "by default"?

2

There are 2 answers

1
Ingo On BEST ANSWER

The actual question is whether JVM keeps track of objects under the hood?

Yes, it does. Garbage collection is the responsibility of the JVM.

Is there an object inside JVM?

Yes, there are byte codes to create class instances. Also, dynamic dispatch of instance methods is done by the JVM.

Is it responsibility of creators of such languages that they may interoperate with Java world, or it is achieved "by default"?

It is low hanging fruit, and it would be foolish not to do it. Moreover, not all JVM languages reinvent the wheel and just use JRE classes when it is appropriate. This includes most probably String, the primitive types and their boxed forms and arrays.

1
s1m0nw1 On

All JVM languages compile to "Java Byte Code". Actually, the JVM does not have any idea of the programming language Java. The JVM spec specifies a "class file", which must fulfill certain rules. As long as you provide compliant class files, created by a compiler e.g., your code will run on a JVM. That's what Kotlin does for example.