https://kotlinlang.org logo
Title
w

w_bianrytree

09/11/2019, 8:53 AM
Hey guys. Is there a way that I can call a method in Java that have a generic boundary? Let’s say my method in Java:
public static <T extends A&B> void methodA()
Where A B are different interfaces I can call the method in Java without any type like this:
methodA()
But when I call that method in kotlin I don’t know what type I should give to it
methodA</*What Should I put it here?*/>()
Any ideas?
g

Giorgio Antonioli

09/11/2019, 9:02 AM
You can use
methodA<A>()
w

w_bianrytree

09/11/2019, 9:07 AM
Thanks. But what if I have 2 boundary? For example:
public static <T extends A & B> void methodAB()
A/B are different interfaces.
m

Matteo Mirk

09/11/2019, 9:11 AM
you could choose either type, depending on your needs. Think about interfaces as “traits” of your object
oh wait, I might be mistaken sorry…
w

w_bianrytree

09/11/2019, 9:15 AM
😉 Np. I was about to say it somehow need a type really suppose those but generic.
r

Ruckus

09/11/2019, 3:33 PM
How on Earth would such a function be useful? That type will be erased at runtime, so the function can't really do anything with it. I guess you could define a placeholder interface:
interface C : A, B
methodA<C>()
1