Hey guys. Is there a way that I can call a method ...
# announcements
w
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:
Copy code
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:
Copy code
methodA()
But when I call that method in kotlin I don’t know what type I should give to it
Copy code
methodA</*What Should I put it here?*/>()
Any ideas?
g
You can use
methodA<A>()
w
Thanks. But what if I have 2 boundary? For example:
public static <T extends A & B> void methodAB()
A/B are different interfaces.
m
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
😉 Np. I was about to say it somehow need a type really suppose those but generic.
r
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:
Copy code
interface C : A, B
methodA<C>()
1