Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [kotlin]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
2 votes
1 answer
122 views

Is returning Result types the standard way of dealing with errors in Kotlin?

Given that there are no checked exceptions in Kotlin, are Result types the correct way to indicate an exception occurred to the caller? For example, I have the following function in my code: suspend ...
Adam's user avatar
  • 272
3 votes
4 answers
392 views

Is there ever a reason in Kotlin to use threads over coroutines?

I have a good understanding of when coroutines in Kotlin are superior to threads. I know that coroutines are lightweight and are great for massive concurrency when, in contrast, spinning up lots of ...
J-bob's user avatar
  • 299
0 votes
1 answer
141 views

Separation of concerns: persisting complex types

I have the following module structure: core persistence extension In my core module, I have an interface: Handler. This interface has multiple implementations in the core module as well as extension ...
alturkovic's user avatar
-1 votes
1 answer
280 views

Using a shared enum across 15 nanoservices [closed]

Originally posted here, moved to code review, redirected from code review back here as there is no code to review. I think the question is enough abstract to be asked here. I have a mono repo with ...
Alexander Petrov's user avatar
-1 votes
1 answer
84 views

When is the application of Kotlin infix functions appropriate? [closed]

The Kotlin language brings the simplification of function calls to the natural language. This article shows a nice example: Function: fun of(suit: Suit) = Card(this, suit) val card = Rank.QUEEN.of(...
Nikolas Charalambidis's user avatar
2 votes
1 answer
79 views

Android Jetpack DataStore item separation

I am trying to migrate to Jetpack DataStore from good ol' SharedPreferences and there is one thing I am struggling to come to terms with and that is the amount/size of the data pulling out of ...
TheLibrarian's user avatar
0 votes
1 answer
436 views

Android + Kotlin + Hilt + multi-module app: Should I "migrate" all classes with static methods to "injection"?

With the purpose of learning Hilt I started "migrating" my multi-module Kotlin app from using classes with static methods as helpers to Hilt injection. After a lot of headaches, now ...
Diego Perez's user avatar
0 votes
1 answer
902 views

Android + Kotlin + Hilt: Dependency Injection vs Static Methods

I've already read this carefully, but still need more clarification. I'm not new to dependency injection, but new to Hilt, and trying to implement Hilt in my multi-module app. The reason? I currently ...
Diego Perez's user avatar
0 votes
0 answers
462 views

Is splitting Android activities/classes into many Kotlin extension functions a good or bad practise?

I have been working on an Android application for some time, and ever since the beginning I've developed a practice of splitting my class's (mostly activity/fragment) code up into multiple files. This ...
thebluepandabear's user avatar
-1 votes
1 answer
156 views

What is the relationship between Java Library and Kotlin?

I wanted to learn Kotlin but after reading online most experts seem to agree that learning Java first would be a first step in the roadmap of learning Kotlin. Their argument based on the fact that ...
Ladan's user avatar
  • 1
0 votes
2 answers
572 views

Which is the best approach I should follow use private fields in data class primary constructor or use Interfaces Inheritance?

I want to perform some operations on data class fields before accessing them and I am confused about which approach I should follow. I want to write code so that it makes sense to everyone and follows ...
Lokik Soni's user avatar
1 vote
1 answer
172 views

How to test functionality that requires a certain internal state?

I'm struggling to test functionality in a class where the class has to be in a certain state for the functionality to work, but the class cannot be put directly into a given state by design, to ...
gotube's user avatar
  • 127
1 vote
2 answers
374 views

Is using KDoc/Javadoc comments inside of a function considered bad practice?

I often find it helpful to use KDoc/Javadoc comments inside of a class or function instead of normal comments. IntelliJ colorizes them more obviously by default and, more importantly, allows ...
Matt Robertson's user avatar
0 votes
2 answers
105 views

Approach for using multiple implementation of one interface for a single class, optional to use all or most of them

Consider an interface: interface Auth { fun doAuth() } this can be implemented for multiple APIs: class GoogleAuth : Auth { override fun doAuth(){ throw NoGoogleAuthImpl(); } } class ...
mrahimygk's user avatar
  • 117
-1 votes
3 answers
137 views

Interface or Object with Type?

I have a calculation program which uses a number of different vertex types. Currently I have euclidean and geo, and I have decided to create an interface. Now I am wondering if that is a good idea. ...
Gunnar Bernstein's user avatar
4 votes
1 answer
198 views

Do kotlin libraries with inline APIs encourage high coupling and discourage unit testing?

As an example, let's assume our application needs some way to communicate with other systems using HTTP. interface HttpClient { fun <T> get(url: String, returnType: Class<T>): T fun ...
enp4yne's user avatar
  • 149
18 votes
7 answers
7k views

Should one prefer a generic version of a function, even if it's not re-used (yet)?

YAGNI might tell us, that in the below implementation the generic version is not needed, as long as the function is only used once. But to me personally, it seems, the generic version is more readable ...
Tobias Hermann's user avatar
2 votes
1 answer
260 views

What is the reasoning behind Kotlin using non-nullable types for Java interop methods?

Considering Kotlin Java Interop: Null Safety and Platform Types Why is code like this legal in Kotlin? fun envString(key: EnvVars): String { return System.getenv(key.toString()) } getenv() can ...
F.P's user avatar
  • 609
-2 votes
2 answers
2k views

How to pass data between multiple project modules

I'm working on a Gradle project that has several modules. The project is implemented in Kotlin. One of these modules is the main entry point to the project, which is the main module. Another module ...
Andrei's user avatar
  • 55
1 vote
0 answers
340 views

Common patterns for Observable data layer on iOS

I am working on learning native iOS development in Swift, and I am trying to find something that is similar to what I've learned in Android development with Kotlin. In particular I am referring to ...
papafe's user avatar
  • 171
6 votes
2 answers
4k views

Why Kotlin doesn't allow assignments as expressions?

Coming from Java, I was surprised to find out that Kotlin doesn't allow assignments as expressions. Is there a reason for that? Java (Works) @Test public void test_x() { List<...
sero's user avatar
  • 169
1 vote
1 answer
301 views

Kotlin delegation, what should I test?

In Kotlin the powerful construct of delegation can be used to extend functionality of existing interfaces by reusing existing implementations. class Demo : Map by HashMap {} Questions: What should I ...
Michiel Leegwater's user avatar
15 votes
4 answers
9k views

When to write extension methods for your own classes?

I recently saw a code base which had a data class Address defined somewhere and then in a different place: fun Address.toAnschrift() = let { address -> Anschrift().apply { // mapping ...
Robert Jack Will's user avatar
37 votes
3 answers
7k views

Why is there no static keyword in Kotlin?

Kotlin is known primarily as a drop-in replacement for Java, but it gets rid of a well-known Java construct: the static keyword. Instead, that class-level functionality is offered mainly by companion ...
user1446's user avatar
  • 492