我得到一个“引用make is ambiguous”编译错误,我不明白.
我有这两种方法
public static <T> T make(String name,Class<T> parentClass,boolean rethrowRuntimeExceptions,Object... params) throws DLException public static <T> T make(String name,Object... params) throws DLException
String className = "clsNme"; String one = "1"; String two = "2"; SimpleFactory.make(className,Object.class,false,one,two);
这是错误
both method <T#1>make(String,Class<T#1>,boolean,Object...) in SimpleFactory and method <T#2>make(String,Class<T#2>,Object...) in SimpleFactory match [javac] where T#1,T#2 are type-variables: [javac] T#1 extends Object declared in method <T#1>make(String,Object...) [javac] T#2 extends Object declared in method <T#2>make(String,Object...)
如果重要,这是PowerMock测试的一部分.这是完整的方法
public void makeCallsMakeWithFalse() throws Throwable { Object expected = mock(Object.class); String className = "clsNme"; String one = "1"; String two = "2"; spy(SimpleFactory.class); doReturn(expected).when(SimpleFactory.class); SimpleFactory.make(className,two); // causes error Object observed = SimpleFactory.make(className,two); // doesn't cause error assertEquals(expected,observed); verifyStatic(); SimpleFactory.make(className,two); // causes error
}
如果有帮助:我使用的是javac 1.8.0_77,Mokito 1.10.19和Powermock 1.6.3.