开发者

Android Java Static Generic Call

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开发者_C百科.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.


I believe you need:

Robolectric.<MyShadow,X>shadowOf_(myInstance).foo(); 

where X is whatever the type of myInstance is.


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜