1
이 코드가이 컴파일 오류를 나타내는 이유를 따르지 않습니다.클래스 래핑 <?> 제네릭 형식 오류
오류는 다음과 같습니다
Type mismatch: cannot convert from TestClass.Wrapper<List<capture#1-of ?>> to TestClass.Wrapper<List<?>>
코드는 다음과 같습니다.
package test.cls;
import java.util.List;
public class TestClass
{
static abstract class Wrapper<A>
{
public abstract A wrapped();
}
public static <A> Wrapper<A> wrap(final A val)
{
return new Wrapper<A>()
{
public A wrapped()
{
return val;
}
};
}
public static void main(final String[] args)
{
final List<?> list = null;
final Class<?> c = null;
final Wrapper<List<?>> wrapList = wrap(list); // Error here
final Wrapper<Class<?>> wrapC = wrap(c); // Error here
}
}
추상 클래스를 인스턴스화하려고합니까? – TheEwook
@ TheEwook 아니요, OP는 익명의 클래스 인스턴스를 반환합니다. –