KaliMa
KaliMa

Reputation: 2060

Declaring a Fragment implementing an interface

I want to declare something like this:

private <Fragment extends MyInterface> fragment;

because I want this fragment to be able to be set to a variety of different self-made Fragment objects that all implement MyInterface.

But it doesn't let me do this.

Is there a way to declare such a Fragment?

Upvotes: 1

Views: 185

Answers (1)

Deal
Deal

Reputation: 116

I think what you're looking for is this:

public interface MyFragmentInterface {
}

public class MyFragment extends Fragment implements MyFragmentInterface {
}

Now to declare a variable:

private MyFragmentInterface fragment;

Upvotes: 2

Related Questions