tateisu
01/23/2019, 8:21 PMtateisu
01/23/2019, 8:21 PMAshutosh Panda
10/17/2019, 3:55 PMpavi2410
10/18/2019, 1:16 PMKotlin compile server is temporarily overloaded
user
10/18/2019, 3:00 PMSam Schilling
10/18/2019, 8:56 PMbjonnh
10/18/2019, 9:50 PMSunil Yadav
10/19/2019, 6:32 PMjmfayard
10/20/2019, 8:58 AMkarelpeeters
10/20/2019, 9:53 AMmutableListOf(0,0,0,0,0)
or MutableList(5) { 0 }
Ashutosh Panda
10/20/2019, 9:54 AMJohn
10/20/2019, 7:10 PMJohn
10/20/2019, 7:11 PMHarry
10/21/2019, 9:46 PMuser
10/22/2019, 2:00 PMuser
10/22/2019, 3:23 PMTravis Griggs
10/23/2019, 3:30 AMvar
to it when/where T is Comparable. The syntax is eluding me. I tried:
var <T : Comparable<T>>Slot.concisely:T
get() = this.value
set(newValue) {
if (this.value != newValue) {
this.value = newValue
}
}
But I’m getting a “Type property of parameter must be used in property type”. What am I missing? I’m guessing a bit at the syntax based this snippet seen in the documentation:
fun <T : Comparable<T>> sort(list: List<T>) { ... }Travis Griggs
10/23/2019, 3:34 AMvar <T : Comparable<T>>Slot<T>.concisely:T
is the correct syntax. I think I see why.Travis Griggs
10/23/2019, 5:36 AMRavindu Liyanapathirana
10/23/2019, 5:51 AMRavindu Liyanapathirana
10/23/2019, 5:51 AMplugins {
id 'idea'
id 'org.jetbrains.kotlin.jvm' version '1.3.50'
id 'org.jetbrains.kotlin.plugin.allopen' version '1.3.50'
id 'org.jetbrains.kotlin.plugin.spring' version '1.3.50'
id 'org.jetbrains.kotlin.plugin.noarg' version '1.3.50'
id 'org.jetbrains.kotlin.plugin.jpa' version '1.3.50
and the jpa
plugin is supposed to annotate the javax.persistence.Entity
annotation to have a no-argument constructor.Ravindu Liyanapathirana
10/23/2019, 5:55 AMRavindu Liyanapathirana
10/23/2019, 5:56 AMCompany::class.createInstance()
where Company
is an @Entity
causes an IllegalArgumentException
with the message "Class should have a single no-arg constructor" 🤔Ravindu Liyanapathirana
10/23/2019, 5:57 AMCompany
is defined as,
@Entity
@Table(name = "company")
data class Company (
// ...
Ravindu Liyanapathirana
10/23/2019, 5:57 AMuser
10/24/2019, 7:00 AMlibiez
10/24/2019, 12:20 PMJoan Colmenero
10/24/2019, 5:48 PMsealed class ResultWrapper<out T> {
data class Success<T>(val data: T) : ResultWrapper<T>()
data class Unauthorized<T>(val exception: UnauthorizedException) : ResultWrapper<T>()
//More error classes
}
I could not get the T when I was using ResultWrapper.
I was using like :
when(function) {
is ResultWrapper.Success -> DoSomething
is ResultWrapper.SomeError -> DoSomething
And I realized that I could not use the value of the return of it, so I found this sealed class
sealed class Either<out L, out R> {
//Failure
data class Left<out L>(val value: L) : Either<L, Nothing>()
//Success
data class Right<out R>(val value: R) : Either<Nothing, R>()
val isRight get() = this is Right<R>
val isLeft get() = this is Left<L>
fun <L> left(a: L) = Left(a)
fun <R> right(b: R) = Right(b)
}
fun <L, R, T> Either<L, R>.fold(left: (L) -> T, right: (R) -> T): T =
when (this) {
is Either.Left -> left(value)
is Either.Right -> right(value)
}
fun <L, R, T> Either<L, R>.flatMap(f: (R) -> Either<L, T>): Either<L, T> =
fold({ this as Either.Left }, f)
fun <L, R, T> Either<L, R>.map(f: (R) -> T): Either<L, T> =
flatMap { Either.Right(f(it)) }
And with this I can do it, the thing is I was using this :
inline fun <reified T : Any> execute(requestFunc: () -> T): ResultWrapper<T> =
try {
ResultWrapper.Success(requestFunc.invoke())
} catch (exception: Exception) {
when (exception) {
is UnauthorizedException -> ResultWrapper.Unauthorized(exception)
is NetworkException -> ResultWrapper.Network(exception)
is BadRequestException -> ResultWrapper.BadRequest(exception)
is NotFoundException -> ResultWrapper.NotFound(exception)
else -> ResultWrapper.Error(exception)
}
}
And then trying to move it to Either
I'm having problems since I have to do something like reified T,R
and the return is Either<T,R>
but then trying to do Either.Right(requestFunc.invoke())
is saying that is expecting a T,R and I'm only returning T.
Any ideas how to achieve it?Marko Mitic
10/25/2019, 12:39 PMconstructor
annotation use-site target make sense? So instead
class Example @Inject constructor(<params>)
we could write
@constructor:Inject
class Example(<params>)