我有这堂课:
public class ActorFixture<T>
{
public T actor;
public String fixture;
public ActorFixture() {}
public ActorFixture(T actor, String fixture)
{
this.actor = actor;
this.fixture = fixture;
}
public void setFixture(Fixture fa, Fixture fb)
{
Class<T> type;
if (type.isInstance(fa))
{
actor = type.cast(fa.getBody().getUserData());
fixture = (String)fa.getUserData();
}
else if (type.isInstance(fb))
{
actor = type.cast(fb.getBody().getUserData());
fixture = (String)fb.getUserData();
}
}
}
但我收到'类型'的警告,因为它没有初始化。
检查类型的正确方法是什么?
答案 0 :(得分:0)
试试这个:
Class<T> type = (Class<T>) this.actor.getClass();