1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-11-05 03:55:58 +01:00

Add example classes to demonstrate usage of Kotlin code from Java and vice versa

This commit is contained in:
Paul Schaub 2023-06-21 15:49:49 +02:00
parent a19b7693e2
commit 0335d7e55d
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
4 changed files with 74 additions and 0 deletions

View file

@ -0,0 +1,16 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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.");
}
}

View file

@ -0,0 +1,20 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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();
}
}

View file

@ -0,0 +1,15 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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!")
}
}

View file

@ -0,0 +1,23 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// 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<String>) {
AccessJavaFromKotlin().run()
}
class AccessJavaFromKotlin {
fun run() {
val java = AJavaClass()
java.doSomething()
}
}