menu
techminis

A naukri.com initiative

google-web-stories
Home

>

Programming News

>

This Code ...
source image

Medium

3w

read

426

img
dot

Image Credit: Medium

This Code Runs in Both Kotlin and Java

  • This article discusses how a program can run in both Kotlin and Java using code-smuggling techniques.
  • The author uses a unique trick involving Unicode escape sequences in Java to hide executable Java code inside what Kotlin thinks is a comment.
  • Kotlin allows nested block comments not permitted in Java, offering a potential way to hide Kotlin code in Java files.
  • The author explores using String literals and dollar-interpolation to conceal Kotlin code inside Java files.
  • By leveraging text blocks and valid Java statements, the article explains how Kotlin code can be hidden in Java programs.
  • These code-smuggling methods enable the creation of polyglot programs that combine Java and Kotlin seamlessly.
  • The author provides insights into how to hide and blend code from both languages effectively.
  • This technique can be extended to merge any pair of Java and Kotlin programs into a single file.
  • The article concludes by challenging readers to find the hidden tricks in the provided polyglot program.
  • Overall, the article showcases creative ways to achieve interoperability between Java and Kotlin within a single codebase.

Read Full Article

like

25 Likes

For uninterrupted reading, download the app