Reputation: 1638
I have been given a project that I have to study & understand. There's a class that has the following: -
public abstract class AbstractPayment extends GodelCheckout {
public static final String AUTH_USING_GET = "GET";
public static final String AUTH_USING_POST = "POST";
@Retention(RetentionPolicy.SOURCE)
@StringDef({AUTH_USING_GET, AUTH_USING_POST})
public @interface AuthMethod {}
I tried understanding annotation & why they are important from Google's Developer site, but I couldn't understand much apart from the fact that they are used for improving code.
But how are they improving code? Any example?
Why is @Retention(RetentionPolicy.SOURCE)
required here?
What does @StringDef()
actually do?
what is public @interface AuthMthod{}
?
Please explain what Retention.SOURCE, .CLASS & .RUNTIME
really are? I tried understanding them from Google's Developer's site, but it didn't help much?
Upvotes: 1
Views: 56
Reputation: 20278
AUTH_USING_GET
or AUTH_USING_POST
can be passed.RUNTIME
the code is inspected during running.@StringDef
allows you to pass only String
id's, for example R.string.login
. @IntDef
allows you to pass only R.id.sample_int
to the functionFor more questions refer to Java documentation.
Upvotes: 2