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