Skip to content

Instantly share code, notes, and snippets.

@vicly
Last active February 19, 2020 00:14
Show Gist options
  • Save vicly/f60bb467625b126e7a51b9d372b9d931 to your computer and use it in GitHub Desktop.
Save vicly/f60bb467625b126e7a51b9d372b9d931 to your computer and use it in GitHub Desktop.
[Java annotation] #Java

Overridden method does NOT inherit annotation

@Inherited
@Target({TYPE, METHOD})
@Retention(RUNTIME)
public @interface MyAnnotation {
	String value() default "hello";
}


@MyAnnotation("super")
class MySuper {
  @MyAnnotation("t1")
  public void t1() {
  }
}

// Auto inherit MySuper's annotation
class MySub extends MySuper {
  // Not inherit, you MUST explicitly declare
  public void t1() {
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment