{{theTime}}

Search This Blog

Total Pageviews

Java 8 Repeating Annotations

@Repeatable is a Java 8 feature allows to run a specific method at a scheduled time.

For example, to check current price and want to use annotations to schedule when methods should be called, you can try something like

@ScheduleGetPrice(dayOfMonth="first")
@ScheduleGetPrice(dayOfWeek="Monday", hour=7)
public void getCurrentPrice() 
{ ... }  

Schedule annotation needs to use meta-annotation @Repeatable like below.

The@Repeatable annotation takes the class of the containing annotation as value

// ScheduleGetPrice.java
@Repeatable(Schedules.class)
public @interface ScheduleGetPrice {...}

// Schedules.java
public @interface Schedules {
   ScheduleGetPrice[] value;  7 
}

Use reflection to access repeatable annotations at run-time. There is a new method called getAnnotationsByType(Class annotationClass) on Class, Constructor, Method, etc.

No comments:

Could not find method signingConfigs() for arguments

Could not find method signingConfigs() for arguments [build_5dw7nwfc8ibd8sagvx4p79x1u$_run_closure5@13e86039] on root project 'android&#...