Reputation: 9651
I'm working with Robolectric, and in the Robolectric class there is a static method:
public static <P, R> P shadowOf_(R instance) {
return (P) ShadowWrangler.getInstance().shadowOf(instance);
}
I've come from a long time C# Generics background so I could be thinking of this incorrectly. My first instinct was to utilize this as such:
Robolectric.shadowOf_<MyShadow>(myInstance).foo();
However, this does not compile (plus, to me and my C# generics background, it doesnt look right).
How can I use this method?
Source of the method is located here.
Upvotes: 0
Views: 226
Reputation: 45443
compiler can't infer what P is. Suppose P should be A here, you can
A a = Robolectric.shadowOf_(myInstance); // compiler can infer P=A here
a.foo();
Upvotes: 0
Reputation: 272517
I believe you need:
Robolectric.<MyShadow,X>shadowOf_(myInstance).foo();
where X
is whatever the type of myInstance
is.
Upvotes: 2