Questions tagged [java-interop]
44 questions
21
votes
2 answers
What's the intended use of @JvmSynthetic in Kotlin?
I have come across the @JvmSynthetic annotation in kotlin-stdlib, and I'm wondering what it is for, but, unfortunately, it is undocumented. (UPD: it was at that moment)
As far as I understand, applying it to a program element will add the synthetic…

hotkey
- 140,743
- 39
- 371
- 326
21
votes
3 answers
Does Clojure have an equivalent of Java's import package.*?
Or do I have to specifically enumerate every class that I import?
I'm just learning Clojure now, and it seems useful to be able to do something like this in the REPL:
(import '(java.io *))
Not that this is valid syntax, but it would be nice to…

Jeff
- 14,831
- 15
- 49
- 59
12
votes
3 answers
Convert static windows library to dll
I have a library contains a bunch of static *lib files, I wish to access them from JNA (a Java library that allows one to dynamically call `dll's from JAVA Code), so is there a way to magically change static lib to dll?
Code was compiled using…

jb.
- 23,300
- 18
- 98
- 136
11
votes
2 answers
Add constructor to deftype created class
For the purposes of interoperability with Java, I need a class that has a nullary constructor that performs initialization.
Objects of this class need to have something resembling mutable java fields (namely, the object represents the backend of a…

Alex R
- 2,201
- 1
- 19
- 32
11
votes
3 answers
Kotlin method overloading
This following declaration is legal in Kotlin.
fun foo(): String = "foo_1"
fun foo(): T = "foo_2" as T
As bytecode we are getting:
public final static foo()Ljava/lang/String;
// signature ()TT;
// declaration: T…

Sergei Rybalkin
- 3,337
- 1
- 14
- 27
10
votes
2 answers
Changing kotlin extension function receiver JVM name
This is a general question.
Let's say I have an extension function written in kotlin which converts DP to PX and return a NonNull Int
fun Int.toPx() { /** implementation */ }
The function in java will look something like this
public int toPx(int…

Gil Goldzweig
- 1,809
- 1
- 13
- 26
10
votes
3 answers
How do I invoke a Java method from perl6
use java::util::zip::CRC32:from;
my $crc = CRC32.new();
for 'Hello, Java'.encode('utf-8') {
$crc.'method/update/(B)V'($_);
}
say $crc.getValue();
sadly, this does not work
Method 'method/update/(B)V' not found for invocant of class…

user7610
- 25,267
- 15
- 124
- 150
8
votes
2 answers
clojure gen-class varargs constructor
in the :constructors map and subsequent -init definitions, how do I represent a varargs constructor (assuming the superclass has multiple constructors of which one is varargs) ?

Hendekagon
- 4,565
- 2
- 28
- 43
7
votes
1 answer
How can I define a clojure type that implements the servlet interface?
I'm attempting to use deftype (from the bleeding-edge clojure 1.2 branch) to create a java class that implements the java Servlet interface. I would expect the code below to compile (even though it's not very useful).
(ns foo [:import…

Rob Lachlan
- 14,289
- 5
- 49
- 99
7
votes
3 answers
How do I pull `static final` constants from a Java class into a Clojure namespace?
I am trying to wrap a Java library with a Clojure binding. One particular class in the Java library defines a bunch of static final constants, for example:
class Foo {
public static final int BAR = 0;
public static final int SOME_CONSTANT =…

Joe Holloway
- 28,320
- 15
- 82
- 92
6
votes
2 answers
How do you refer to primitive Java types in Clojure?
I'd like to use reflection to get a method of a Java object from Clojure. One of the argument types is a Java primitive and I don't know how to refer to them from Clojure.
For example, say I wanted to get String.valueOf(boolean). My nearest guess…

Jeremy
- 1
- 85
- 340
- 366
5
votes
3 answers
Converting Java collections to Clojure data structures
I am creating a Clojure interface to a Java API with a method that returns a java.util.LinkedHashSet.
Firstly, is the idiomatic Clojure way of handling this to convert the LinkedHashSet to a clojure data structure?
Secondly, what is the best method…

Toby Hede
- 36,755
- 28
- 133
- 162
5
votes
2 answers
Clojure - convert list into Java array
Is there any idiomatic way of converting Clojure list into Java array, other than first converting it to vector and using into-array (means, something other than (into-array (vec my-list)), as I don't want additional overhead)?

Arnthor
- 2,563
- 6
- 34
- 54
4
votes
1 answer
Inherited platform declarations clash when extending a Java class in Kotlin
I am trying to extend a third-party Java class with Kotlin but I get this compiler message:
Inherited platform declarations clash: The following declarations have
the same JVM signature (setCollection(Ljava/util/Collection;)V):
fun…

Christian Kaufmann
- 53
- 6
3
votes
1 answer
In Karate, what is the advantage of wrapping a Java function in a JavaScript function?
I can wrap a Java function like this:
* def myJavaMethod =
"""
function() {
var Utils = Java.type('Utils');
// use Number type in constructor
var obj = new Utils(...);
return obj.myJavaMethod();
}
"""
But why would I? I can use…

user2943111
- 421
- 1
- 5
- 15