Mellisa Cartright
Mellisa Cartright

Reputation: 13

new to android - <integer> syntax is confusing

I understand everything except the < integer > part of this code:

private final class MessageListener implements SocialAuthListener<Integer> {
    @Override
    public void onExecute(String provider, Integer t) {
        Integer status = t;
        if (status.intValue() == 200 || status.intValue() == 201 || status.intValue() == 204)
            Toast.makeText(ShareButtonActivity.this, "Message posted on " + provider, Toast.LENGTH_LONG).show();
        else
            Toast.makeText(ShareButtonActivity.this, "Message not posted on " + provider, Toast.LENGTH_LONG).show();
    }

    @Override
    public void onError(SocialAuthError e) {

    }
}

can someone explain what it means? i tried to look through java documentation but couldnt find anything

Upvotes: 0

Views: 89

Answers (1)

koljaTM
koljaTM

Reputation: 10262

SocialAuthListener is an interface that can deal with different types of Object, as denoted by the class in the <>. In this case MessageListener implements it with respect to handling Integer objects.

Read about "Generics". An important example of this are Collections that can hold all kinds of different Objects, but you can tell the compiler to only allow a certain type. A List will use the exact same bytecode as a List, but the compiler will make sure, that only Integer objects are passed in.

Upvotes: 1

Related Questions