Fork me on GitHub
#clojure
<
2021-12-30
>
dealy66304:12:06

I'm running Intellij Idea #IC-213.5744.223 on Apple M1 Silicon. Everything seems to run in Arm64 mode, except for when I'm inside an Intellij terminal. If I run something like lein repl or test-refresh from within that terminal it starts as a rather slow x86 process instead of Arm64. Any idea what might be causing this? Running the exact same command on the same project in a regular iterm2 window starts as arm64.

pez14:12:11

Long time ago since I did any Java… It impairs my Java interop skills as well. 😃 I have this

package pez;

public class HelloWorld {
    public HelloWorld() {

    }
    
    public static void main(String[] args) {
        System.out.println("Hello, World!"); 
    }

    public static String foo() {
        return "foo";
    }

    public String bar() {
        return "bar";
    }
}
I can import it in a Clojure file but can’t figure out how to use it:
(HelloWorld.) => Syntax error (IllegalArgumentException) compiling new at (src/pez/java_test/java_hello.clj:5:9). No matching ctor found for class pez.HelloWorld
(HelloWorld/foo) => Syntax error (NoSuchFieldException) compiling . at (src/pez/java_test/java_hello.clj:6:3). foo
What am I not getting?

Linus Ericsson14:12:38

A static method should be called with the class (not an instance of the class). (pez.HelloWorld/foo) should return "foo"

Linus Ericsson14:12:20

the instance method bar should work with (.bar (pez.HelloWorld.)) => "bar"

Linus Ericsson14:12:20

also, the HelloWorld.class file can be of an old version in the /target if you have made changes to it.

pez14:12:21

I am calling foo statically there, ain’t I? I am importing this using (:import [pez HelloWorld])

Linus Ericsson14:12:15

seems right. is the class-file freshly and correctly compiled?

Linus Ericsson14:12:49

and does the (.bar ...) thing work?

pez14:12:16

It compiles without complaints. Don’t see any target directory, though. Nor any .cpcache...

pez14:12:07

(.bar …) doesn’t work, because (HelloWorld.) doesn’t work.

pez14:12:36

Restarting the repl helped. Now it works.

💫 1
pez14:12:11

I wonder how I could refresh that class w/o such a brute method…

pez14:12:31

It’s a deps.edn project.

Linus Ericsson14:12:27

I think Java is not able to reload classes once they are loaded. It could be possible to create a new class-loader (clojure does a lot of class-loader related things under the hood).

🙏 1
pez14:12:29

Actually I could (ns-unmap 'pez.java-hello 'pez.HelloWorld), then import again.

pez14:12:50

No, I was too quick to conclude. It imported the old definition. ¯\(ツ)

clj 1