Loading Kotlin generated classes at runtime from Java - kotlin

I have 2 projects...
My main java project and a kotlin sub project that I moved some java classes out of the main project into and converted into kotlin.
I've configured the kotlin project to have a dependency on the main java project, it works quite well since IJ is constantly recompiling java classes in the main project.
But now that i've extracted classes from the Java project, it won't compile anymore of course - it needs to access the kotlin project.
However, I don't know how to do that.. can someone explain? thanks
my kotlin out folder is empty whenever I look at it

Kotlin generates perfectly ordinary Java class files, so you can use Class.forName() and Class<?>.getConstructor().getNewInstance() with them just as well as with classes compiled from Java source code.

Related

What does "common" mean in kotlin documentation?

In kotlin standard library documentation i can see the following filters:
As far as i can gather, JVM means that internals of a package can be compiled into byte code, JS into javaScript and Native into binaries. But what does "Common" mean ?
Common means available for all platforms. It is an API that you can use directly in platform independent code in Kotlin Multiplatform projects.
Kotlin Multiplatform allows you to write common Kotlin code for multiple different platforms. For example, you could have a project with an Android app (using Kotlin/JVM for native Android applications) and a web interface (using Kotlin/JS). Then, you could share code between both subprojects.
As you have guessed correctly, JVM means it is available using Kotlin/JVM (compiling to Java bytecode).
If it is marked with JS, it is available for Kotlin/JS which transpiles the Kotlin code to JavaScript.
Finally, Native means it is available when using Kotlin/Native. This is different from compiling with native-image, which compiles JVM bytecode to native executables. For that, you would still use Kotlin/JVM.
If you write code in "common", then it can be compiled into any of the other targets, so you can share Kotlin code amongst the different platforms you are targeting. You can read more in the documentation.

Can I build a windows executable from kotlin source code?

As far as I know, kotlin native allows you to compile kotlin source code to platform specific nativ code, that runs without any virtual machine.
But I don't seem to find any example on how to build a windows executable (.exe) from kotlin source code.
Why is that?
Can you do it or not?
https://kotlinlang.org/docs/native-get-started.html shows you how to set up a basic Kotlin Native project, and compile it. The only note is that kotlin native will generate a .kexe, which is just a renamed .exe.

Strange "Unresolved reference:" error after upgrading to Kotlin 1.0.5

I have a project that contains 2 modules. A Java module that contains my java code. And a Kotlin module that contains my Kotlin code. The Kotlin module depends on the java module. That is, there is nothing in the Java module that references the Kotlin module. But the Kotlin module relies on Java classes from the Java module.
This project I haven't opened for 6 months or so.
It worked fine before. It was kotlin 1.something. Whatever was the latest in June.
Now I have updated to the latest Kotlin version.
But one of my java module java classes cannot be referenced anymore from the Kotlin module. It is only 1 of the classes, the Kotlin module references a lot of other classes from the Java module just fine still.
I am hoping someone can tell me what is going on. Maybe there were some changes to Kotlin in the last 6 months that cause this?
The message I get in all Kotlin files in the Kotlin module that reference JSBot is this:
Error:(191, 39) Kotlin: Unresolved reference: JSBot
The JSBot import in the kt files is correct. Other classes from the Java module even in the same java package are recognized and compile without errors.
Here is the JSBot.java declaration (in the java module):
public abstract class JSBot extends Evaluable implements Name {
...
}
Other abstract java classes are referenced fine though from the Kotlin module. So I can't really understand what is going on. It is just this one Java class.
But, in earlier Kotlin versions (v1.0 through whatever was latest in June) it compiled fine. I just get this error now. I haven't changed any code. Only updated to kotlin plugin 1.0.5
Could anyone give me some hints what to do? I am stuck and can't figure out where to go from here.
I updated my maven .pom to 1.0.5 from 1.0.0, but that didn't help.
seems to be resolved, issue will be fixed in Kotlin release described in comments above. Please don't delete this question, it might be helpful to others that encounter this kotlin bug.

Libraries, projects, modules and packages in Intellij Idea

I'm a beginner programmer and I'm learning how to work with Intellij IDEA. A project in IntelliJ IDEA has some different structures like libraries, modules and packages.
Can someone explain what the difference is between those structures and when to use a particular structure? e.g. I can't choose my package name (of a class) arbitrarily when it's already part of a module. What is the connection between those? I'm primarily having difficulties understanding the difference between a package and a module. (characters)
A project in intellij consists of modules. Modules can be java modules, or android modules or whatever. Modules contain your java code and all that stuff. A Module can reference a library which can be a project library or a global library. Global libraries have to be defined only once. Project library in every project you need them.
Packages are a java concept and are IDE independent.
Lets say I wanna do a little game. I would create a intellij Project called "mySuperGame". Then I would create two java modules from intellij, called "logic" and "ui". In the module settings of "ui" I would specify a project library to use opengl and a dep. to "logic". The package name of my logic classes would be "com.mysupergame.logic.XXX".
See http://confluence.jetbrains.com/display/IDEADEV/Structure+of+IntelliJ+IDEA+Project for more information.
IntelliJ IDEA supports everything eclipse has. But vise versa might not be true. Please check this table for the differences. IntelliJ support intelligent perspective and has many windows.
Read the documentation from IntelliJ idea.
Below comparison between Visual Studio (.NET) and IntelliJ (Java), which might be helpful for .NET developers migrating to Java:

Why does IntelliJ import extra libraries from JDK 1.6 for a simple hello world program?

I'm new to Java and IntelliJ and I am just doing a simple "hello world" program. IntelliJ has about 10+ libraries from JDK 1.6 added to my project even though I'm not importing anything in my classes that would seem to need them. I created a new project from scratch.
Some of the libraries are alt-rt.jar, charsets.jar, deploy.jar, dnsns.jar, javaws.jar, jce.jar, jsse.jar, localedata.jar, etc.
Can anyone explain why those libraries were added? Can I remove those libraries from the Module Settings/SDK with no ill effect?
They will be in the classpath anyways as they are part of the standard library. I'm not sure what will happen if you remove them, but you definitely don't need to do that.
These libraries aren't imported in your project, intelliJ has just parsed these jar to see what were the accessibles classes (for auto-completion) with the default classpath.
They won't be packaged with your project.
Plus as your JDK (or any SDK for what it worth) is defined for intelliJ and not for your project only, every project you will create in the future will use the already parsed data from your JDK.