Kotlin Operator Overloading
Random Thoughts on Java Programming
by
1w ago
So my colleague mentioned operator overloading, and how much fun it is. So I wrote a little test. It works pretty good, but for infix functions it has a very high "syntactic sugar" and less about "real" operator overloading. Also, the reference page in [1] indicates that for Infix functions, the precedence has fixed rules that do not (always) conform to precedence that we would assume. My colleague told me that a number of infix functions were created for QueryDSL, so we could write a semblance of SQL in Kotlin, but the precedence tends to screw things up. We removed these infix functions from ..read more
Visit website
Kotlin: listOf() versus emptyList()
Random Thoughts on Java Programming
by
3w ago
So I noticed that Kotlin tends to have several ways of doing the same thing1. Sometimes these are actually identical, sometimes there are subtle differences. That makes things hard for me. Let's take this trivial example. There is no difference. The one thing you could mention is that emptyList() more accurately conveys what you are trying to do. There's something similar in Java. Collections.emptyList() versus List.of(). The comments on [2] seems to be very interesting. In Java one could argue that List.of() is new, so should be used. And we could assume that the Language Architects in Java w ..read more
Visit website
Java - Behaviour of Equals in Collections
Random Thoughts on Java Programming
by
1M ago
I just thought I'd write some things down that I already know, but sometimes it's nice to see this proven. It's a very very beginner Java subject, but people won't fault me for blogging about it. It might be of some use to somebody ..read more
Visit website
Reinitializing IntelliJ
Random Thoughts on Java Programming
by
2M ago
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.plu ..read more
Visit website
Kotlin and Java and Interfaces and Automatic Getters and Setters
Random Thoughts on Java Programming
by
3M ago
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 (getDescript ..read more
Visit website
Postgres and Migrating Databases
Random Thoughts on Java Programming
by
3M ago
So, it's doable to transfer all data from an Oracle database structure into a similar (hopefully exactly the same) database structure in Postgres. One of the problems you encounter, is the Foreign Keys. These will get triggered when inserting data . Now, in a perfect scenario, you know that the Oracle database structure, which also has the same Foreign Keys, is fine, so we won't need to check the Foreign Keys in Postgres when inserting data. You cannot turn off Foreign Keys in Postgres, however, Postgres automatically creates system triggers for Foreign Keys that check if referential integrity ..read more
Visit website
Kotlin Scope Functions
Random Thoughts on Java Programming
by
3M ago
Scope function examples below: let with run apply also takeIf and takeUnless Using them all at the same time!!! I really hope I'm not the only one that gets confused about the different Scope functions1 in Kotlin and what they mean and when to use what. The reference in [1] is excellent, but if I have to look up documentation on what certain methods do, the methods are not very well named. So, in short, here's some examples, actually gleaned from the documentation and given my own spin on it with things that actually make sense. Let /** * Useful if you do not wish to assign the re ..read more
Visit website
Solution: Problems with Kotlin
Random Thoughts on Java Programming
by
3M ago
Well, the solution to [1] is obviously that you are missing a "&&". This causes Kotlin to assume the expression: it.address.country == "United Kingdom" ... is the expression that needs to be returned. This causes the code to spit out all people currently in the United Kingdom. It took me a little while to notice the problem. My IDE didn't help in the slightest. References [1] Problems with Kotlin ..read more
Visit website
Problems with Kotlin
Random Thoughts on Java Programming
by
3M ago
So, I was working and it didn't work. And I really could not understand why. Here's the code: @Test fun test() { val addressInNetherlands = Address(housenumber = 11L, street = "Kerkstraat", city = "Amsterdam", state = null, country = "Netherlands") val addressInEngland = Address(12, "Morsestreet", "London", null, "United Kingdom") val anotherAddressInEngland = Address(28, "Trinity Ln", "Cambridge", null, "United Kingdom") val addressInAmerica = Address(23, "32nd Street", "Columbus", "Ohio", "United States of America") val mrBear ..read more
Visit website
Git: Adding your own commands
Random Thoughts on Java Programming
by
5M ago
So I do have a habit of adding my own commands, simply as an alias, simply in the startup scripts of my *nix account and it works fine. But apparently it also can be done inside git. So in the example in [1], the new command is "git eradicate". It was added to the ~/.git-config file as: eradicate = "!git reset --hard; git clean -fdx" "-fdx" will also remove files that are mentioned in the .gitignore file. As there are settings in there, this is perhaps not what you want. According to the manual in [2] regarding git clean, the option "-x" has the following interesting effect: "Don’t use the sta ..read more
Visit website

Follow Random Thoughts on Java Programming on FeedSpot

Continue with Google
Continue with Apple
OR