From 0335d7e55dc379397a8b0a49108b49e084fbbf09 Mon Sep 17 00:00:00 2001 From: Paul Schaub Date: Wed, 21 Jun 2023 15:49:49 +0200 Subject: [PATCH] Add example classes to demonstrate usage of Kotlin code from Java and vice versa --- .../kotlin_experiments/AJavaClass.java | 16 +++++++++++++ .../AccessKotlinFromJava.java | 20 ++++++++++++++++ .../kotlin_experiments/AKotlinClass.kt | 15 ++++++++++++ .../java_from_kotlin/AccessJavaFromKotlin.kt | 23 +++++++++++++++++++ 4 files changed, 74 insertions(+) create mode 100644 wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/AJavaClass.java create mode 100644 wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/kotlin_from_java/AccessKotlinFromJava.java create mode 100644 wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/AKotlinClass.kt create mode 100644 wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/java_from_kotlin/AccessJavaFromKotlin.kt diff --git a/wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/AJavaClass.java b/wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/AJavaClass.java new file mode 100644 index 00000000..512e83e8 --- /dev/null +++ b/wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/AJavaClass.java @@ -0,0 +1,16 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package org.pgpainless.kotlin_experiments; + +public class AJavaClass { + + /** + * Some method in a Java class. + * Used by {@link org.pgpainless.kotlin_experiments.java_from_kotlin.AccessJavaFromKotlin}. + */ + public void doSomething() { + System.out.println("Something has been done."); + } +} diff --git a/wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/kotlin_from_java/AccessKotlinFromJava.java b/wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/kotlin_from_java/AccessKotlinFromJava.java new file mode 100644 index 00000000..7fb39a7e --- /dev/null +++ b/wot-dijkstra/src/main/java/org/pgpainless/kotlin_experiments/kotlin_from_java/AccessKotlinFromJava.java @@ -0,0 +1,20 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package org.pgpainless.kotlin_experiments.kotlin_from_java; + +import org.pgpainless.kotlin_experiments.AKotlinClass; + +/** + * Example class to verify that we can access Kotlin classes from our Java code \o/. + * Accesses {@link AKotlinClass} and executes {@link AKotlinClass#printToStdout()}. + */ +public class AccessKotlinFromJava { + + public static void main(String[] args) { + // from src/kotlin/.../ + AKotlinClass kotlin = new AKotlinClass(); + kotlin.printToStdout(); + } +} diff --git a/wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/AKotlinClass.kt b/wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/AKotlinClass.kt new file mode 100644 index 00000000..3142f1e3 --- /dev/null +++ b/wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/AKotlinClass.kt @@ -0,0 +1,15 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package org.pgpainless.kotlin_experiments + +/** + * Some Kotlin class that is used by AccessKotlinFromJava in src/main/java/... + */ +class AKotlinClass { + + fun printToStdout() { + println("'Hello, World' from Kotlin!") + } +} \ No newline at end of file diff --git a/wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/java_from_kotlin/AccessJavaFromKotlin.kt b/wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/java_from_kotlin/AccessJavaFromKotlin.kt new file mode 100644 index 00000000..71e26dc2 --- /dev/null +++ b/wot-dijkstra/src/main/kotlin/org/pgpainless/kotlin_experiments/java_from_kotlin/AccessJavaFromKotlin.kt @@ -0,0 +1,23 @@ +// SPDX-FileCopyrightText: 2023 Paul Schaub +// +// SPDX-License-Identifier: Apache-2.0 + +package org.pgpainless.kotlin_experiments.java_from_kotlin + +import org.pgpainless.kotlin_experiments.AJavaClass + +/** + * Verify that we can access Java code from the Kotlin codebase. + * Accesses [AJavaClass] and executes [AJavaClass.doSomething]. + */ +fun main(args: Array) { + AccessJavaFromKotlin().run() +} + +class AccessJavaFromKotlin { + + fun run() { + val java = AJavaClass() + java.doSomething() + } +} \ No newline at end of file