1
我想在方法調用中提供一個接口。取決於給定的接口,該方法應該創建一個實例。爲此我使用泛型爲該方法提供不同類型的接口。這裏的一個例子:接口作爲方法參數
static <T> T createClient(T, String endpointAddress) {
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean()
factory.setServiceClass(T.class)
factory.setAddress(endpointAddress)
(T) factory.create() // error -> java.lang.IllegalArgumentException: java.lang.Class is not an interface
}
// AccessibleClient is an interface. call method
createClient(AccessibleClient, "http://localhost/service")
我不知道我的方法是適當的解決方案。
不該「它是'createClient(T參數,字符串endpointAddress)'? – sanbhat
您如何期望從界面創建實例? – Apurv
它應該是'createClient(AccessibleClient.class,「http:// localhost/service」)' – gontard