Day 4 - What I like about Kotlin
April 9, 2026•426 words
Part of Listed's 100 Day Writing Challenge.
Honestly, brain empty. Decided to just write about what I like about Kotlin over Java simply because I was coding out a SMTP Email sender service in Kotlin.
Also, my favorite programming language is still Java. Yes, I still love my AbstractSingletonProxyFactoryBean or a legendary AssignedPrincipalsWithTransitiveWithDirectoryScopeTypeWithDirectoryScopeIdRequestBuilder.
What I like about Kotlin
Honestly, its just the way it handles null safety compared to Java that leads to less boilerplate.
Null Safety
Kotlin has a lot of ways to deal with null handling, and null safety is part of it's type system. In Java? Its manual checks, null related annotations, or straight to NullPointerException.
Also, the null safety in Kotlin is enforced by the compiler. In Java, its mostly enforced via annotations.
?: and ?. operator
Pretty useful to remove boilerplate when you deal with null values. As a simple example, my application accepts optional CLI Arguments, such as SMTP_Protocol:
val smtpProtocol = sources.optionalString("SMTP_Protocol") ?: "smtp",
In this case, if my optionalString does return null, the smtpProtocol will default to an "smtp" value.
You can also use it to make early returns or throws, for example:
object LoggingConfigurator {
private val managedLoggers = listOf("Main", "MailConfig", "SmtpMailSender")
fun configure(levelName: String) {
val normalized = levelName.uppercase()
val level = Level.toLevel(normalized, null)
?: throw IllegalArgumentException("Invalid Log_Level: $levelName. Use TRACE, DEBUG, INFO, WARN, or ERROR")
val context = LoggerFactory.getILoggerFactory() as? LoggerContext ?: return
context.getLogger(Logger.ROOT_LOGGER_NAME).level = level
managedLoggers.forEach { loggerName ->
context.getLogger(loggerName).level = level
}
}
}
Basically, this is a helper object to manage and configure loggers. The key parts are:
val level = Level.toLevel(normalized, null)
?: throw IllegalArgumentException("Invalid Log_Level: $levelName. Use TRACE, DEBUG, INFO, WARN, or ERROR")
Pretty simple, if the conversion to a Level enum fails, early exit via throwing an exception. And also,
val context = LoggerFactory.getILoggerFactory() as? LoggerContext ?: return
In here, as? allows the conversion to fail by returning a null instead. Chained together with ?: return, it will make an early exit if LogBack is unavailable.
Less boilerplate, less OCD.
Kodee
Afterword
There are other good things about Kotlin when compared to Java, since this is just a blog about my opinion, just wanted to share how much I like the way it deals with Null Safety to make less boilerplate code.
Also, not to say Java, Kotlin or any language for that matter, is the best. All languages are good, and have their own philosophy or solve different problem statements.