Thursday, 26 December 2024

Reinitializing IntelliJ

Every once in a while, you get into trouble, serious trouble, and the only solution is to clear out all your stuff and start again.

This recently happened to me when my IntelliJ started misbehaving. I didn't have time to fix it, so I just bore with it, but now it's time to fix it.

In order to remove all the settings of IntelliJ (That I thought were the problem), I found the link at [2] via [1] which helped a lot!

And since I'm using a MacBook M2, perhaps I should write them down here:

Configuration (idea.config.path): ~/Library/Application Support/JetBrains/IntelliJIdea2022.2
Plugins (idea.plugins.path): ~/Library/Application Support/JetBrains/IntelliJIdea2022.2/plugins
System (idea.system.path): ~/Library/Caches/JetBrains/IntelliJIdea2022.2
Logs (idea.log.path): ~/Library/Logs/JetBrains/IntelliJIdea2022.2

Above are the directories that you should either remove or move somewhere safe (in case you want to reuse settings, like for example database connection properties).

Removing IntelliJ settings from a Project

So, if I've done the above, good idea to also remove the settings that are project specific.

This should be as simple as finding the ".idea" directory in your project and removing it entirely. But an alternate way is just removing all unversioned files and changes from your version management system, that'll work too.

I found a good way of doing it using the Git versioning system and described it in [3].

Then what?

Well, unfortunately, after all that it's time to reimport your project into IntelliJ and configuring all your IntelliJ settings again.

Preferably by hand, to prevent the same problem that torpedoed your Intellij from happening again.

References

[1] StackOverflow - In IntelliJ on OS X, how do you clear out all global setting info, licensing etc. (external to any project)
https://stackoverflow.com/questions/2774315/in-intellij-on-os-x-how-do-you-clear-out-all-global-setting-info-licensing-etc
[2] IntelliJ Support - Directories used by the IDE to store settings, caches, plugins and logs
https://intellij-support.jetbrains.com/hc/en-us/articles/206544519-Directories-used-by-the-IDE-to-store-settings-caches-plugins-and-logs
[3] Git: Adding your own commands
https://randomthoughtsonjavaprogramming.blogspot.com/2024/10/git-adding-your-own-commands.html

Thursday, 19 December 2024

Kotlin and Java and Interfaces and Automatic Getters and Setters

Kotlin is great, Java is great, but there are sometimes little things that can be a little bit tricky. Especially when combining the two.

I am going to talk about one tricky thing now.

So we have an interface in Java:

And I wish to implement it using an enum in Kotlin.

Like so:

Obviously this will break, because a public val description automatically gets a getter in Kotlin, which conflicts with the implementation of the getDescription method.

You'll get error messages during compile time like this:

Platform declaration clash: The following declarations have the same JVM signature (getDescription()Ljava/lang/String;):
Platform declaration clash: The following declarations have the same JVM signature (getDescription()Ljava/lang/String;):

Well, you think, that's fine. If Kotlin already makes a getDescription automatically, I can simply remove my method getDescription() from the enum.

But that doesn't work. It immediately starts complaining that you have not implemented all members of the interface.

The way to solve it is to make the description field private ("private val description: String") so Kotlin no longer automatically creates a getter.

Trivial but a bit surprising.

From what I can tell, Kotlin is being careful not to create what they call "accidental overrides".

References

YouTrack - KT-6653 - Kotlin properties do not override Java-style getters and setters (created 10 years ago)
https://youtrack.jetbrains.com/issue/KT-6653
YouTrack - KT-19444 - Add JVM-specific annotation to permit "accidental" overrides of interface members
https://youtrack.jetbrains.com/issue/KT-19444