Hello, World! A small API design question: I'm ma...
# announcements
b
Hello, World! A small API design question: I'm making a lib in Kotlin, and want to make it nice to use from Kotlin and Java. One method takes a date range as a parameter so I used a
Pair<Date>
for it. This way from Kotlin it's nice, you can do
foobar(dateFrom to dateTo)
. But from Java you're going to have to do
foobar(new kotlin.Pair<>(dateFrom, dateTo))
and now you need Kotlin in your dependencies for this to work - not cool. Ideally I'd like to have both
to
and not this Java issue... Ideas?
t
I'm making a lib in Kotlin, and want to make it nice to use from Kotlin and Java
write it in java
b
and how do you make
to
work in Java?
m
"and now you need Kotlin in your dependencies for this to work - not cool" -- AFAIK a runtime dependency is unavoidable if your library is in Kotlin. If you want to avoid the Kotlin runtime dependency, you would need to implement the library in Java via a
foobar(Date, Date)
method. You could offer a Kotlin wrapper library that has your
foobar(Pair<Date>)
API via an extension function.
b
allright, well 🙂 I'll make a
DateRange
class then. Yeah the extension sounds good. Thanks
l
You could also just use two parameters
k
Also consider using
..
instead of
to
if it's really a range.
âž• 1
b
Actually this method already have more parameters, that's why an ad-hoc class is preferable.
..
may be cool indeed yes