I don't understand the documentation:
Package-Level Functions
All the functions and properties declared in a file example.kt inside a package org.foo.bar, including extension functions, are compiled into static methods of a Java class named org.foo.bar.ExampleKt.
// example.kt
package demo
class Foo
fun bar() {
}
// Java
new demo.Foo();
demo.ExampleKt.bar();
my code below.
compile error; build failed:
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ gradle compileJava
> Task :compileJava
/home/thufir/NetBeansProjects/kotlin/src/main/java/net/bounceme/dur/kotlin/App.java:12: error: package demo does not exist
new demo.Foo();
^
/home/thufir/NetBeansProjects/kotlin/src/main/java/net/bounceme/dur/kotlin/App.java:13: error: package demo does not exist
demo.ExampleKt.bar();
^
2 errors
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileJava'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 0s
1 actionable task: 1 executed
thufir@dur:~/NetBeansProjects/kotlin$
java source:
package net.bounceme.dur.kotlin;
import java.util.logging.Logger;
public class App {
private static final Logger LOG = Logger.getLogger(App.class.getName());
private void run() {
LOG.info("running");
new demo.Foo();
demo.ExampleKt.bar();
}
public static void main(String[] args) {
new App().run();
}
}
kotlin source:
package demo;
class Foo
fun bar() {
}
project:
thufir@dur:~/NetBeansProjects/kotlin$
thufir@dur:~/NetBeansProjects/kotlin$ tree
.
├── build
│ ├── classes
│ │ └── java
│ │ └── main
│ └── tmp
│ └── compileJava
├── build.gradle
├── gradle
│ └── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── settings.gradle
└── src
├── main
│ ├── java
│ │ └── net
│ │ └── bounceme
│ │ └── dur
│ │ └── kotlin
│ │ └── App.java
│ └── kotlin
│ └── example.kt
└── test
└── java
└── AppTest.java
18 directories, 9 files
thufir@dur:~/NetBeansProjects/kotlin$