Skip to content

Instantly share code, notes, and snippets.

@MaksimDmitriev
Created October 8, 2023 14:49
Show Gist options
  • Select an option

  • Save MaksimDmitriev/cfea491b64333a9a31f2ce9ab9cfc28a to your computer and use it in GitHub Desktop.

Select an option

Save MaksimDmitriev/cfea491b64333a9a31f2ce9ab9cfc28a to your computer and use it in GitHub Desktop.
JvmField, JvmName, JvmOverloads, JvmStatic
package ru.maksim.sample
class Foo {
@JvmField
val a = 1
@JvmName("getStr")
fun getB() = a.toString()
@JvmOverloads
fun bar(
k: Int = -1,
l: String = "abc",
m: Int = 1,
) {
println("k = $k, l = $l, m = $m")
}
companion object {
@JvmStatic
val CONST = 1
@JvmStatic
fun baz() {
println("baz")
}
}
}
package ru.maksim.sample;
import org.junit.jupiter.api.Test;
public class SampleJavaTest {
@Test
public void test() {
final Foo foo = new Foo();
foo.bar(1);
foo.getStr();
Foo.Companion.baz();
Foo.baz();
System.out.println(Foo.getCONST());
}
}
package ru.maksim.sample
import org.junit.jupiter.api.Test
class SampleKotlinTest {
@Test
fun foo() {
val foo = Foo()
foo.getB()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment