0

I have this class:

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();
        }
    }
}

But I get a warning on 'type' because it's not initialized.

What's the correct way to check the type?

Ivan-Mark Debono
  • 15,500
  • 29
  • 132
  • 263

1 Answers1

0

Try this:

Class<T> type = (Class<T>) this.actor.getClass();
brso05
  • 13,142
  • 2
  • 21
  • 40