https://kotlinlang.org logo
Title
a

Andreas Sinz

12/03/2017, 12:31 PM
@robstoll any reason you need to specify the type?
r

robstoll

12/03/2017, 12:33 PM
Unfortunately yes, I saw that it works if I do not have to
c

czyzby

12/03/2017, 12:40 PM
You don't. This works for me:
fun main(args: Array<String>) {
    1 doStuff 1.2
}

infix fun <T> Int.doStuff(t: T) { println(t) }
r

robstoll

12/03/2017, 1:14 PM
I am using it in a generic function, something like
fun <T> foo(a: T){ 1 test<T> a }
ok, bad example as well 😄 let me check the usage
my function is actually defined likes this:
infix inline fun <reified TSub : Any> IAssertionPlant<Any>.isA(noinline assertionCreator: IAssertionPlant<TSub>.() -> Unit)
That's why I need to provide a type for
TSub
r

rkeazor

12/03/2017, 4:32 PM
can you put that into a code block in slack. its hard to read like that
r

robstoll

12/03/2017, 6:15 PM
It is already in a code block, I'll put the parameter on a new line:
infix inline fun <reified TSub : Any> IAssertionPlant<Any>.isA( 
    noinline assertionCreator: IAssertionPlant<TSub>.() -> Unit
)
r

rkeazor

12/03/2017, 7:14 PM
shouldn’t it be IAssertionPlant<Tsub>
?
r

robstoll

12/03/2017, 7:42 PM
in case you mean
IAssertionPlant<Any>
, then nope
isA
is basically a down-cast assertion which allows you to tell that
val a: Any = 1; assert(a).isA<Int>{}
for instance