mirror of
https://github.com/pgpainless/pgpainless.git
synced 2024-12-24 11:57:59 +01:00
Add example classes to demonstrate usage of Kotlin code from Java and vice versa
This commit is contained in:
parent
a19b7693e2
commit
0335d7e55d
4 changed files with 74 additions and 0 deletions
|
@ -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.");
|
||||||
|
}
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
|
@ -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!")
|
||||||
|
}
|
||||||
|
}
|
|
@ -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()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue